KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Encode and Decode Base64
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: September 9, 2004
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Base64 encoding is often used to compress the size of streams of data, usually being transported over a network. For example, SOAP uses the XML Schema type base64binary to allow users to more efficiently transport large chunks of information that can be, but are not limited to, pictures or files.

In previous versions of 4D, it was necessary to use the Internet Commands Toolkit plugin for base64 encoding and decoding, and that also required file save and load operations. New in 4th Dimension 2004, however, are two commands ENCODE and DECODE that allow you to perform the same operations with blobs.

Take the following example:

C_BLOB($blob)
C_TEXT($string)

$string:="4D 2004 is cool!"
TEXT TO BLOB($string;$blob;Text without length )

ENCODE($blob)
$string:=BLOB to text($blob;Text without length )

DECODE($blob)
$string:=BLOB to text($blob;Text without length )

This example first encodes the text "4D 2004 is cool!" into "NEQgMjAwNCBpcyBjb29sIQ==" in base64 with the command ENCODE. Then, the command DECODE changes it back.