# ToBase64

Calculates the Base64 representation of a string or binary object.

The Base64 format uses printable characters, allowing binary data to be sent in forms and e-mail, and stored in a database or file.

## Method Signature

```
ToBase64(string_or_object=[any], encoding=[string])
```

### Arguments

| Argument           | Type     | Required | Description                                                                  | Default |
| ------------------ | -------- | -------- | ---------------------------------------------------------------------------- | ------- |
| `string_or_object` | `any`    | `true`   | A string or a binary object.                                                 |         |
| `encoding`         | `string` | `false`  | The character encoding (character set) of the string, used with binary data. | `UTF-8` |

## Examples

### String Example

Converts a String to a Base64-String.

[Run Example](https://try.boxlang.io/?code=eJwLyXdKLE41M9FQUApJLS5RCC4pysxLV1LQtOYCAHaPB%2Fo%3D)

```java
ToBase64( "Test String" );

```

Result: VGVzdCBTdHJpbmc=

### Binary Object Example

Converts an Image Binary to a Base64-String.

```java
ToBase64( ToBinary( ImageRead( "example.jpg" ) ) );

```

### Additional Examples

[Run Example](https://try.boxlang.io/?code=eJxLKc0t0FAIyXdKLE41M9FQUIIxlRQ0FTStuRT09RXC3C2dIyP8cvyyAm25AFw%2BDSQ%3D)

```java
dump( ToBase64( "ToBase64" ) );
 // VG9CYXNlNjQ=

```

## Related

* [DataNavigate](/boxlang-language/reference/built-in-functions/conversion/datanavigate.md)
* [JSONDeserialize](/boxlang-language/reference/built-in-functions/conversion/jsondeserialize.md)
* [JSONPrettify](/boxlang-language/reference/built-in-functions/conversion/jsonprettify.md)
* [JSONSerialize](/boxlang-language/reference/built-in-functions/conversion/jsonserialize.md)
* [LSParseNumber](/boxlang-language/reference/built-in-functions/conversion/lsparsenumber.md)
* [ParseNumber](/boxlang-language/reference/built-in-functions/conversion/parsenumber.md)
* [ToBinary](/boxlang-language/reference/built-in-functions/conversion/tobinary.md)
* [ToModifiable](/boxlang-language/reference/built-in-functions/conversion/tomodifiable.md)
* [ToNumeric](/boxlang-language/reference/built-in-functions/conversion/tonumeric.md)
* [ToScript](/boxlang-language/reference/built-in-functions/conversion/toscript.md)
* [ToString](/boxlang-language/reference/built-in-functions/conversion/tostring.md)
* [ToUnmodifiable](/boxlang-language/reference/built-in-functions/conversion/tounmodifiable.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://boxlang.ortusbooks.com/boxlang-language/reference/built-in-functions/conversion/tobase64.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
