Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
491 มุมมอง

Binary field on any model with attachment True or False with binary widget or not it is all downloading the file as zip.

How do i download it as the way i first put into it?

อวตาร
ละทิ้ง
ผู้เขียน

thanks it worked. i need more karma to count the answer so ill just leave it as it is

คำตอบที่ดีที่สุด

Hi,

You have a Binary field (e.g., file upload), and when users download the file, it's always downloaded as a .zip file even if you originally uploaded a PDF, DOCX, XLSX, etc.


To preserve the original file format, you must set the filename in a separate field and bind it to the binary field using the filename attribute in the form view.


1. Define a filename field in your model:



from odoo import models, fields


class MyModel(models.Model):

    _name = 'my.model'


    attachment = fields.Binary(string="File")

    attachment_filename = fields.Char(string="Filename")


2. In the view (form.xml):


<field name="attachment" filename="attachment_filename"/>


This tells Odoo to download the binary content using the value in attachment_filename.


Hope it helps

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Add the download_link widget in XML with a valid filename_field.

Ensure the filename field is populated with the correct extension.

Avoid zippering unless needed for multiple files.

Use standard download actions to retain file integrity.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.ค. 24
31
1
มี.ค. 25
1109
1
พ.ย. 24
1130
0
ส.ค. 24
1051
Stock And Point Of Sale FIFO in Odoo 17 แก้ไขแล้ว
1
ก.ค. 24
1104