简体   繁体   中英

Download binary files with python

I'm developing with Odoo framework and when I get a binary file value from database I need to download it.

It's any module for doing it with python?

    @http.route(['/permissions/print/<int:permission_id>'], type='http', auth="public", website=True)
    def print_docr(self, permission_id=None):
        perm_id = request.env['res.partner.permission'].sudo().browse(permission_id)
        print(perm_id.attachment_doc)

This is the output of the file. 在此处输入图像描述

Any suggestion? Thanks for reading!

I'm not sure I understood what you want, but it seems that you're downloading base64 strings to represent your binary files. If this is the case, you can firstly convert it to a bytes string:

from base64 import b64decode

bytes_string = b64decode(perm_id.attachment_doc)

Then writing it on a file:

with open("filename.bin", 'wb') as f:
    f.write(bytes_string)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM