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

I want to download binary file. I know about widget binary type, I want to download it directly and save it in browser.

How can I pass binary file, so that it could be saved direct as `save as` file?

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

Hello,

Use something like below, it will automatically download the file:

import base64
# output is where you have the content of your file, it can be
# any type of content
output 
# encode
result = base64.b64encode(output.read())
# get base url
base_url = self.env['ir.config_parameter'].get_param('web.base.url')
attachment_obj = self.env['ir.attachment']
# create attachment
attachment_id = attachment_obj.create(
{'name': "name", 'datas_fname': 'name.file_ext', 'datas': result})
# prepare download url
download_url = '/web/content/' + str(attachment_id.id) + '?download=true'
# download
return {
"type": "ir.actions.act_url",
"url": str(base_url) + str(download_url),
"target": "new",
}


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มี.ค. 16
4826
0
ธ.ค. 24
1495
How to set attachments to public? แก้ไขแล้ว
1
มี.ค. 23
6709
2
เม.ย. 22
4150
0
ต.ค. 21
2674