In many Odoo projects, you may need to upload files or show images directly on a form. For example, you might want to upload a product photo, attach a document, or display a customer’s signature. Odoo makes this easy using Binary and Image widgets.
Let’s see how you can create and use them in Odoo 19.
What Are Binary and Image Widgets?
- Binary Widget: lets you upload and store any type of file, such as PDFs, Excel sheets, or ZIPs.
- Image Widget: used for uploading and showing images, such as photos or logos.
So if you need to upload a document, use a Binary field.
If you need to show an image, use an Image field.
Step 1: Create the Model
First, create a new model to store file and image data in your custom module
-*- coding: utf-8 -*-
from odoo import models, fields
class ProductAttachment(models.Model):
_name = 'product.attachment'
_description = 'Product Attachment Example'
name = fields.Char(string="Attachment Name", required=True)
file_data = fields.Binary(string="File")
file_name = fields.Char(string="File Name")
image = fields.Image(string="Image")
Notes:
- fields.Binary can hold any file type.
- fields.Image is made for images and Odoo automatically keeps multiple image sizes.
- The file_name field helps save the uploaded file with its proper name.
Step 2: Create the Form and Tree Views
Next, add XML views so users can upload and see files and images.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_product_attachment_form" model="ir.ui.view">
<field name="name">product.attachment.form</field>
<field name="model">product.attachment</field>
<field name="arch" type="xml">
<form string="Product Attachment">
<sheet>
<group>
<field name="name"/>
<field name="file_data" filename="file_name" widget="binary"/>
<field name="file_name" invisible="1"/>
</group>
<group>
<field name="image" widget="image"/>
</group>
</sheet>
</form>
</field>
</record>
<record id="view_product_attachment_list" model="ir.ui.view">
<field name="name">product.attachment.list</field>
<field name="model">product.attachment</field>
<field name="arch" type="xml">
<list>
<field name="name"/>
<field name="file_name"/>
<field name="image" widget="image" options="{'size': [50, 50]}"/>
</list>
</field>
</record>
<record id="action_product_attachment" model="ir.actions.act_window">
<field name="name">Attachments</field>
<field name="res_model">product.attachment</field>
<field name="view_mode">list,form</field>
</record>
<menuitem id="menu_product_attachment_root" name="Product Attachments" sequence="10"/>
<menuitem id="menu_product_attachment" name="Attachments" parent="menu_product_attachment_root" action="action_product_attachment"/>
</odoo>
Explanation:
- shows a file upload option.
- <field name="file_data" widget="binary"/>: shows a file upload option.
- <field name="image" widget="image"/>: shows an image preview and lets you upload a new one.
- The filename="file_name" link keeps the right file name when you download it.
- options="{'size': [50, 50]}" controls the image thumbnail size in list view.
Step 3: Change Image Size (Optional)
You can adjust how the image looks using the options tag.
Example:
<field name="image" widget="image" options="{'size': [128, 128]}"/>
Or show a specific image size stored by Odoo:
<field name="image" widget="image" options="{'preview_image': 'image_1024'}"/>
Step 4: Test It Out
Once your code is ready:
- Add your model and views in __manifest__.py.
- Update your app list and upgrade your module.
- Go to Product Attachments > Attachments and try uploading files and images.

You can upload files using the ‘Upload your file’ button and the images using the pen button.
You should be able to:
Upload any file type (PDF, DOCX, ZIP, etc.)
Upload and preview images

That’s it. You’ve built working Binary and Image widgets in Odoo 19.
Binary fields are ideal for storing documents such as invoices or contracts.
Image fields make your app look better by showing product photos, user images, or company logos.
Both widgets are simple to use and can fit easily into any custom Odoo module.
To read more about How to Create a Widget in Odoo 18, refer to our blog How to Create a Widget in Odoo 18.