Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
7741 Ansichten

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?

Avatar
Verwerfen
Beste Antwort

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",
}


Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
0
März 16
4777
0
Dez. 24
1475
1
März 23
6658
2
Apr. 22
4116
0
Okt. 21
2651