콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
622 화면

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.

아바타
취소
관련 게시물 답글 화면 활동
0
7월 24
31
1
3월 25
1237
1
11월 24
1190
0
8월 24
1120
1
7월 24
1175