KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Sending Text with SEND HTML BLOB command
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: June 9, 2000

If you are trying to create an HTML document in a 4D text variable and then send it using SEND HTML BLOB, you may be tempted to use the command VARIABLE TO BLOB. However, VARIABLE TO BLOB is intended to be used for storing and retrieving the values of 4D variables in BLOBs, and as such includes extra information in the BLOB that specifies the type of the variable and optionally its length. Page 238 of the Language Reference states:

"WARNING: If you use a BLOB for storing variables, you must later use the command BLOB TO VARIABLE for reading back the contents of the BLOB, because variables are stored in BLOBs using a 4D internal format."

The correct command to use for sending HTML is TEXT TO BLOB. When using this for web serving you always want to call it with the option of "Text without length" as follows in this sample code:

Cut and Paste the following code example into your
own 4D project

C_TEXT($tHTML)
C_BLOB($bHTML)
$tHTML:="" ` begin HTML, begin HEAD
$tHTML:=$tHTML+"Test HTML Document"
$tHTML:=$tHTML+"" ` end HEAD
$tHTML:=$tHTML+"This is some test HTML"
$tHTML:=$tHTML+"" ` end HTML
TEXT TO BLOB($tHTML;$bHTML;Text without length )
SEND HTML BLOB($bHTML;"text/html")