Binary Data Type And Base64 Encoding - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

How ColdFusion stores dates and times
ColdFusion stores and manipulates dates and times as date-time objects. Date-time objects store
data on a time line as real numbers. This storage method increases processing efficiency and
directly mimics the method used by many popular database systems. In date-time objects, one
day is equal to the difference between two successive integers. The time portion of the date-and-
time value is stored in the fractional part of the real number. The value 0 represents 12:00 AM
12/30/1899.
Although you can use arithmetic operations to manipulate date-and-time values directly, this
method can result in code that is difficult to understand and maintain. Use the ColdFusion date-
time manipulation functions instead. For information on these functions, see the CFML
Reference.

Binary data type and Base64 encoding

Binary data is raw data, such as the contents of a GIF file or an executable program file. You do
not normally use binary data directly, but you can use the
variable, typically for conversion to Base64 encoding before transmitting the file using e-mail.
Base64 format encodes the data in the lowest six bits of each byte. It ensures that binary data and
non-ANSI character data can be transmitted using e-mail without corruption. The MIME
specification defines the Base64 encoding method.
ColdFusion does not have a Base64 data type; it processes Base64 encoded data as string data.
ColdFusion provides the following functions that convert among string data, binary data, and
Base64 encoded string data:
Function
Description
ToBase64
Converts string and binary data to Base64 encoded data.
ToBinary
Converts Base64 encoded data to binary data.
ToString
Converts most simple data types to string data. It can convert numbers, date-time
objects, and boolean values. (It converts date-time objects to ODBC timestamp
strings.) It cannot convert binary data that includes bytes that are not printable
characters.
The
function cannot convert Base64 encoded data directly to an unencoded string. Use
ToString
the following procedure to convert Base64 encoded data that was originally a string back to a
readable string:
Use the
1
ToBinary
Use the
2
ToString
For example, the following two lines print the same results:
<cfoutput>Hello world</cfoutput>
<cfoutput>#ToString(ToBinary(ToBase64("Hello world")))#</cfoutput>
Do not use binary data or Base64 data directly in ColdFusion expressions.
60
Chapter 3: Using ColdFusion Variables
function to convert the Base64 data into binary format.
function to convert the binary data to string data.
tag to read a binary file into a
cffile

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents