[Google Apps Script] Encode a string in Base64

Created on November 28, 2026

The Utilities.base64Encode method can encode a Byte[] value in Base64. To encode a string with this approach, first convert the string to Byte[]. In the example below, Utilities.newBlob() creates a blob from HelloWorld, and getBytes() returns its bytes.

function main() {
  var blob = Utilities.newBlob('HelloWorld');
  console.log(Utilities.base64Encode(blob.getBytes()));
}

The example produces the following output.

SGVsbG9Xb3JsZA==
Google Apps Script