---
schema_version: "1"
id: a3b8e732a3fa93fa4555019a88902a320f66aadfd0b1c0f1c4362fe1c1a59b11
title: toBase64
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/dataweave/2.9/dw-binaries-functions-tobase64.md
canonical_url: https://docs.mulesoft.com/dataweave/2.9/dw-binaries-functions-tobase64
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 0d2ed9c13ff57691e8318d35320562add3fb0a1ac4049ef93236488cf99fb952
description: MuleSoft Documentation Site
release: "2.9"
latest: false
---
---
product: DataWeave
version: 2.9
---

# toBase64

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

## toBase64(content: Binary): String

Transforms a binary value into a Base64 string.

### Parameters

<table><colgroup><col> <col></colgroup><thead><tr><th>Name</th><th>Description</th></tr></thead><tbody><tr><td><p><code>content</code></p></td><td><p>The binary value to transform.</p></td></tr></tbody></table>

### Example

This example transforms a binary value into a Base64 encoded string. In this case, the binary value
represents an image.

#### Source

```DataWeave
%dw 2.0

import dw::Crypto
import toBase64 from dw::core::Binaries

var emailChecksum = Crypto::MD5("achaval@gmail.com" as Binary)
var image = readUrl(log("https://www.gravatar.com/avatar/$(emailChecksum)"), "application/octet-stream")

output application/json
---
toBase64(image)
```

#### Output

This example outputs a Base64 encoded string. The resulting string was shortened for readability
purposes:

```JSON
"/9j/4AAQSkZJRgABAQEAYABgAAD//..."
```
