Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
9008 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
2
feb 23
9276
2
mag 18
11540
0
lug 16
4522
2
giu 16
9968
1
gen 18
5830