Xbasic
base64Encode Function
Syntax
EncodedString as C = base64Encode(B data)
Arguments
- dataBinary
The data to base64 encode.
Returns
- EncodedStringCharacter
A base64 encoded version of the binary data.
Description
Encode (to string) binary data using base64.
Discussion
The base64Encode() function returns a string in base64 format encoded from binary data of arbitrary length. Because the data is now represented by the ASCII character set, it is suitable for transmission as text in email.
The encoded data does not include any data prefixes, which may be required to embed your base64 encoded data in HTML markup. You also need to URL encode the base64 data before embedding it in HTML.
This function can be used to convert an image into base64 encoded format for embedding in HTML. For example:
dim filedata as b dim filename as c = "mydata.png" dim result as P filedata = a5storage_getitem_as_blob("::storage::disk",filename,result) dim img64 as c img64 = base64Encode(filedata) ? img64 = "iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=="
See Also