This question has been flagged
2 Replies
19695 Views

Hello every one here i am again, Does anyone knows how to display filename of a binary file? I tried to make it downloadable but upon the execution of the wizzard it shows only the "Download" without its filename and upon downloading it's filename become the name of my class plus there is no file extension. The downloaded file is something like this: custom_report_1 (i want to bear it's filename base on how i set it and it's extension). How can i resolve this? Pls help.

Avatar
Discard

How you solved this problem?

Best Answer

From Odoo 16 You need to add widget="binary" as well :


<field name="odometer_image" filename="odometer_image_name" widget="binary"/>
<field name="odometer_image_name" invisible="1"/>



Avatar
Discard

Hello,
Does not work if you ese pdf_viewer widget instead

Best Answer

You have to create a char field and then link it with binary field in xml file using filename attribute.

Ex:

# create a char field
file_data = fields.Binary('File')
file_name = fields.Char('File Name')

# Go to xml and
<field name="file_data" filename="file_name"/>
<field name="file_name" invisible="1"/>
Avatar
Discard

but this solution cant effect when file_data show in tree view.

it just show capacity of file

You have a file_name field that stores the name of the file. So just add file_name field in a tree view instead of file_data field if you just want to show the file name in the tree view.