Python Developer Guide
Other documentationsDemoCommunityGitHub
  • Forest Admin
  • Getting started
    • How it works
    • Quick start
      • Flask
      • Django
    • Create your agent
    • Troubleshooting
    • Migrating legacy agents
      • Pre-requisites
      • Recommendations
      • Migration steps
      • Code transformations
        • API Charts
        • Live Queries
        • Smart Charts
        • Route overrides
        • Smart Actions
        • Smart Fields
        • Smart Relationships
        • Smart Segments
  • Data Sources
    • Getting Started
      • Collection selection
      • Naming conflicts
      • Query interface and Native Queries
        • Fields and projections
        • Filters
        • Aggregations
    • Provided data sources
      • SQLAlchemy
      • Django
        • Polymorphic relationships
    • Write your own
      • Translation strategy
        • Structure declaration
        • Capabilities declaration
        • Read implementation
        • Write implementation
        • Intra-data source Relationships
      • Contribute
  • Agent customization
    • Getting Started
    • Actions
      • Scope and context
      • Result builder
      • Static Forms
      • Widgets in Forms
      • Dynamic Forms
      • Form layout customization
      • Related data invalidation
    • Charts
      • Value
      • Objective
      • Percentage
      • Distribution
      • Leaderboard
      • Time-based
    • Fields
      • Add fields
      • Move, rename and remove fields
      • Override binary field mode
      • Override writing behavior
      • Override filtering behavior
      • Override sorting behavior
      • Validation
    • Hooks
      • Collection hook
      • Collection override
    • Pagination
    • Plugins
      • Write your own
    • Relationships
      • To a single record
      • To multiple records
      • Computed foreign keys
      • Under the hood
    • Search
    • Segments
  • Frontend customization
    • Smart Charts
      • Create a table chart
      • Create a bar chart
      • Create a cohort chart
      • Create a density map
    • Smart Views
      • Create a Map view
      • Create a Calendar view
      • Create a Shipping view
      • Create a Gallery view
      • Create a custom tinder-like validation view
      • Create a custom moderation view
  • Deploying to production
    • Environments
      • Deploy on AWS
      • Deploy on Heroku
      • Deploy on GCP
      • Deploy on Ubuntu
    • Development workflow
    • Using branches
    • Deploying your changes
    • Forest Admin CLI commands
      • init
      • login
      • branch
      • switch
      • set-origin
      • push
      • environments:create
      • environments:reset
      • deploy
  • Under the hood
    • .forestadmin-schema.json
    • Data Model
      • Typing
      • Relationships
    • Security & Privacy
Powered by GitBook
On this page
  • Summary
  • Switching between modes
  • Using the hexadecimal mode
  • Using the data-URI mode

Was this helpful?

  1. Agent customization
  2. Fields

Override binary field mode

PreviousMove, rename and remove fieldsNextOverride writing behavior

Last updated 11 months ago

Was this helpful?

This is the official documentation of the forestadmin-agent-django and forestadmin-agent-flask Python agents.

In Forest Admin, binary fields are not handled specially: they are included in the payloads that transit between your agent and the UI like any other field. To achieve that they are either encoded using the or in .

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 be able to handle both cases, Forest Admin has two distinct modes available.

Summary

hex mode

datauri mode

Best suited for

Compact data (identifiers, hashes, ...)

Large data (files)

Description

The binary data is encoded in hexadecimal representation.

The binary data is encoded using the data-URI scheme.

Example

0xdeadbeef

data:image/png;base64,...

UI widget

Textual representation

File picker / viewer

Default mode

Field is used as either a primary or foreign key

Field 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.

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.

If you want to use the hexadecimal mode for another field, use the replace_field_binary_mode method:

agent.customize_collection('people').replace_field_binary_mode('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, ...).

If the automatic detection based on the field type is not working for you, you can force the datauri mode using the replace_field_binary_mode method as so:

agent.customize_collection('people').replace_field_binary_mode('avatar', 'datauri')

You will need to update the widget manually using the feature.

When using that mode, you will be able to use both the and the widgets in the UI to respectively preview and upload files.

UI customization ↗
File Viewer ↗
File Picker ↗
data-URI scheme ↗
hexadecimal representation ↗
Fields in Hex and modes