base64_encode_tostring function encodes a string into Base64 format. Use this function when you need to encode data for transmission or storage in systems that only support text-based formats, such as APIs, configuration files, or log analysis pipelines.
For users of other query languages
If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.Splunk SPL users
Splunk SPL users
In Splunk SPL, you might not have a built-in Base64 encoding function and would typically rely on external scripts or commands. In APL,
base64_encode_tostring provides native Base64 encoding directly in your queries.ANSI SQL users
ANSI SQL users
In ANSI SQL, Base64 encoding typically requires database-specific functions like
TO_BASE64() in MySQL or custom functions. APL provides base64_encode_tostring as a standard function.Usage
Syntax
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| value | string | Yes | The input string to be encoded as Base64. |
Returns
Returns the input string encoded as a Base64 string.Use case examples
- Log analysis
- OpenTelemetry traces
- Security logs
Encode HTTP content types for secure transmission or storage in Base64 format.QueryRun in PlaygroundOutput
This query encodes the content type of each HTTP request into Base64 format, which is useful when you need to pass content types through systems that have character restrictions.
| _time | content_type | encoded_content_type |
|---|---|---|
| 2024-11-06T10:00:00Z | application/json | YXBwbGljYXRpb24vanNvbg== |
| 2024-11-06T10:01:00Z | text/html | dGV4dC9odG1s |
List of related functions
- base64_decode_tostring: Decodes a Base64-encoded string back to its original UTF-8 format. Use this when you need to reverse the encoding operation.
- base64_encode_fromarray: Encodes an array of bytes into a Base64 string. Use this when working with binary data rather than text strings.
- base64_decode_toarray: Decodes a Base64 string into an array of bytes. Use this when you need to work with the raw binary representation.
- url_encode: Encodes a URL string for safe transmission. Use this when working with URLs rather than general text encoding.