JavaScript global method: base64Encode

Converts binary data to a base 64 string format.

Syntax

base64Encode( data );

Arguments

The following arguments are valid for this function:

Argument Data type Required Description
data Binary Yes This argument contains the data you want the script to encode in base 64 format.

Return values

A string object containing the data in base 64 format.

Description

This method converts binary data to a base 64 string format. You can also use this method to encode plain text data in base 64 format.

Example

This example does the following:

  • Reads the contents of a binary file
  • Converts the file to a base 64 string format
  • Prints the base 64 string

This example requires the following sample data:

  • A binary file on the local file system (for example, an image file)
var source = readFile( "C:\\header_left.gif", "b" );
var encode = base64Encode( source );
print( "The value of encode is:\n" + encode );