Contact Free trial Login

toBase64

toBase64(Binary): String

Transforms a binary value into a Base64 string.

Parameters

Name Description

content

The binary value to transform.

Example

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

Source

%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:

"/9j/4AAQSkZJRgABAQEAYABgAAD//..."

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub