Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
8545 Weergaven

Hello.

I have an API that returns file content as base64 encoded bites. I need to let user download or preview the file (best would be both). My idea was to put base64 bites to binary field and in the view use binary widget. However the binary field does not understand the mime type of the file, thus making the mime type to octet-stream and then not representing it correctly. 

Is there a way to provide mime type to binary field (API returns the mime type of the file), so it would understand what kind of file it is?

What other way I can show/download the file from the API in odoo temporary?

P.S. I cannot save the file in odoo system because of security reasons and not to duplicate files.

Thank you for your answers in advance.

Avatar
Annuleer
Beste antwoord

Unfortunately, the Binary field does not allow to specify the mimetype as far as I know.

However, there are workarounds. You can create the attachment manually and set it: env['ir.attachment'].create with mime_type. Instead of a Binary field, you can use a relation to the attachment.

Sometimes Odoo computes this attachment relation, for example in addons/delivery/models/stock_picking.py#_compute_return_label . In the view, it uses a link to /web/content/{id}

Another possibility is to create a custom route for your file where you set the Content-Type accordingly.

Avatar
Annuleer
Gerelateerde posts Antwoorden Weergaven Activiteit
2
feb. 23
8506
2
mei 18
11205
0
jul. 16
4240
2
jun. 16
9663
1
jan. 18
5527