Skip to main content
In Forest, binary fields are included in the payloads that transit between your back-end and the UI like any other field. To achieve that, they are either encoded using the data-URI scheme or in hexadecimal representation. Binary fields in databases are usually either used to store compact data (like a hash or an identifier) or large data (like an image). To handle both cases, Forest has two distinct modes available.

Summary

hex modedatauri mode
Best suited forCompact data (identifiers, hashes, …)Large data (files)
DescriptionThe binary data is encoded in hexadecimal representationThe binary data is encoded using the data-URI scheme
Example0xdeadbeefdata:image/png;base64,...
UI widgetTextual representationFile picker / viewer
Default modeField is used as either a primary or foreign keyField is not used as either a primary or foreign key

Switching between modes

Note that as both modes result in a textual representation of the binary data, changing the mode will not affect the widget used in the UI. You will need to update the widget manually using the UI customization feature.

Using the hexadecimal mode

The hexadecimal mode is suitable for all data that you would not save in a file. It is the default mode for all binary fields that are used as either a primary or foreign key. To use the hexadecimal mode for another field, use the replaceFieldBinaryMode method:
agent.customizeCollection('people', collection =>
  collection.replaceFieldBinaryMode('avatar', 'hex'),
);

Using the data-URI mode

The data-URI mode is suitable for all data that you would save in a file (images, PDFs, …). When using that mode, both the File Viewer and the File Picker widgets are available in the UI to respectively preview and upload files. If the automatic detection based on the field type is not working for you, force the datauri mode using the replaceFieldBinaryMode method:
agent.customizeCollection('people', collection =>
  collection.replaceFieldBinaryMode('avatar', 'datauri'),
);