Create a BLOB attribute in an object

With the introduction of classes in the 4D environment, the need to store your data in objects, and especially blobs, has increased. That’s why 4D v19 R2 lets you encapsulate blobs in objects.

Beyond the storage aspect, since the blob object is a reference type, your performance in terms of memory occupation and speed will be greatly improved.

You can now assign a blob as an attribute of an object like you do for numbers, text, or other types:

$o:=New object("blob"; $blob)

or by implicit conversion:

$o:=New object
$o.blob:=$blob

or with a shared object:

$sObj:=New shared object("blob"; $blob)

In a lot of cases, it is better to use a blob object (4D.Blob type) instead of a Blob type. For example, when you pass a blob object in a method or a command parameter, it is not duplicated like a Blob type but passed by reference, just like any other 4D object. This is faster and less memory-consuming:

var $blobObj : Object
 
// Download your MIME in a blob object
$blobObj:=IMAP_transporter.getMIMEAsBlob ( $msgID )
 
// The BLOB object is then passed to the AddToArchives method by reference.
AddToArchives($blobObj)
// Unlike when you pass a Blob type, the blob is not duplicated when handled using a blob object.

But the standard Blob type is not deprecated. Each blob type has its advantages. Use the following table to determine which one suits your needs:

  Blob 4D.Blob
Alterable Yes No
Shareable in objects and collections No Yes
Passed by reference* No Yes
Performance when accessing bytes +
Maximum size 2GB* Memory

*This size limit may be lower depending on your OS and how much space is available.

Check out the documentation to learn more about this new attribute type!

Now that blobs are managed in objects, there is only one more step for it to be managed in ORDA. Stay tuned!

Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.