KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Setting Blobs in Objects
PRODUCT: 4D | VERSION: 17 | PLATFORM: Mac & Win
Published On: January 24, 2019

It is not possible to set a blob into an object's property value directly. However, it is possible to easily convert the blob into a supported format.

A simple method of doing so is to use BASE64 ENCODE which will encode the blob into a resulting text formatted data. Text data types are allowed to be set into an object's property value. When using the data, it can be reverted using BASE64 DECODE.

Example:
LIST TO BLOB stores a list into a blob as an internal 4D format. As such it cannot be converted to text or any other format directly and can only be used by using BLOB to list. To insert such a blob into an object the BASE64 ENCODE can be used:

//...
C_BLOB($varBlob_bl)
C_TEXT($encodedBlob_t)
C_OBJECT($myObject_ob)

LIST TO BLOB($listRef;$varBlob_bl)
BASE64 ENCODE($varBlob_bl;$encodedBlob_t)
$myObject_ob:=New Object("List";$encodedBlob_t)

Then if the list needs to be used or loaded the following would be used:
//...
C_BLOB($listBlob_bl)

$myObject_ob:=New Object("List";$encodedBlob_t)
BASE64 DECODE($myObject_ob.List;$listBlob_bl)
$listRef:=BLOB to list($listBlob_bl)