# Override binary field mode

{% hint style="success" %}
This is the official documentation of the `forestadmin-agent-django` and `forestadmin-agent-flask` Python agents.
{% endhint %}

![Fields in Hex and  modes](/files/dIJTUjD7aP9WR7LFcqXv)

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 [data-URI scheme](https://en.wikipedia.org/wiki/Data_URI_scheme) or in [hexadecimal representation](https://en.wikipedia.org/wiki/Hexadecimal).

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.

You will need to update the widget manually using the [UI customization](https://docs.forestadmin.com/user-guide/collections/customize-your-fields#edit-settings) 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.

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

```python
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, ...).

When using that mode, you will be able to use both the [File Viewer](https://docs.forestadmin.com/user-guide/collections/customize-your-fields/display-widgets#file-viewer) and the [File Picker](https://docs.forestadmin.com/user-guide/collections/customize-your-fields/edit-widgets#file-picker) widgets in the UI to respectively preview and upload files.

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:

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.forestadmin.com/developer-guide-agents-python/agent-customization/fields/binary.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
