ORDA: Assigning a path to a blob or picture attribute

Non-ORDA database commands allowed you to put images and blobs outside your data file thanks to the SET EXTERNAL DATA PATH command. This command is not adapted for ORDA, so we have decided to add similar functionality in v20 R3: The ability to assign to a blob or picture attribute a path pointing to a file. Let me tell you more about it.

HDI Path for picture

First thing first, let’s look at this bit of code:

var $myRecord:=ds.MyTable.new()
$myRecord.image:="C:/FolderWithMyFiles/myImage"
$myRecord.binary:="C:/FolderWithMyFiles/myBinary"
$myRecord.save()

The image and binary attributes are a picture attribute and a blob attribute, respectively. By assigning a path to them instead of an actual picture or blob, 4D will only put the path provided inside the data file. Only when you use the picture or the blob that 4D will load the file from the disk and create a proper picture or blob variable. For you, it will be completely transparent.

Advantages and precautions

This way of doing it has a few advantages:
– You don’t store binary files inside your data file. As a consequence, your data file stays smaller and faster to maintain.
– You can use the same file for multiple records without duplicating the file’s content.
– You can organize the files however you want and use them with software outside 4D.

But there are also a couple of precautions you need to take:
– As 4D needs the file on the disk, you must be sure it stays accessible whenever 4D accesses it.
– When you assign a path to a picture or blob, it bypasses the “Stored” field property in the database structure (the “Stored” property allows you to choose where to store the content of the picture or blob between the data file or an external data file).

POSIX path or 4D.File

The first code assigns a POSIX path to the attribute (only POSIX paths are accepted). Another solution is to assign a 4D.File like in this example:

var $file:=File("/PACKAGE/FolderWithMyFiles/myImage")
$myRecord:=ds.MyTable.new()
$myRecord.image:=$file
$myRecord.save()

This code will assign the path of the 4D.File to the attribute.

What if you change the file on the disk?

Well, this is a tricky question. As 4D stores the content of blobs and pictures inside its cache, nothing may happen until you close and reopen your application. If you really want to be able to change the file on runtime, there’s one trick you can use: Assign the path to the attribute once again. As 4D will detect a new value, it will clean its cache, and as such, you’ll get the new file the next time you use the picture or blob.
Note: Remember to clear the browser cache if you access the image or blob through a browser, such as Qodly or Data Explorer.

Use the forum if you have any questions.

You can check the documentation to learn how to use this new feature. And if you have any questions or comments, don’t hesitate to contact our forum. We will be more than happy to help you. 

Nicolas Brachfogel
Product Owner & Senior Developer - Nicolas Brachfogel joined 4D in 2017 as senior developer (4D Server and networking) and as Product Owner to manage the 4D version on Apple Silicon. He is tasked with the redaction of user stories and functional specifications, as well as the verification that the new features are in line with customers' needs. With a degree from Institut Supérieur d'Informatique Appliquée Paris (INSIA), Nicolas started his career as a software developer in 2001. After many years of development in Java and C++, he specialized himself in client-server development in the video game industry. As a developer/software architect, he worked on the server architectures of many games (Dofus Arena, Drakerz, Trivial Pursuit Go !).