Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
8952 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
lut 23
9165
2
maj 18
11512
0
lip 16
4479
2
cze 16
9940
1
sty 18
5784