Reputation: 159
i can't find a way to convert the image_1920 field to a string (base64), someone knows how to do it I would appreciate your help
I've done this but it doesn't convert it to str
base64.b64encode(record.image_1920)
The field is of this type!
Note: Odoo14 Community
How do I get the base64?
Upvotes: 0
Views: 1300
Reputation: 159
what I did is bring the record ir.attachment
, then I get the absolute path of the image file and that's it!
att = self.env['ir.attachment'].sudo().search([('id', '=', res[0])])
valores = self.env['ir.attachment'].sudo()._get_datas_related_values(att.datas,
att.mimetype)
dir = self.env['ir.attachment']._full_path(valores['store_fname'])
with open(dir, "rb") as image_file:
data = image_file.read()
decode = data.decode("utf-8")
return decode #base64 file
Upvotes: 1
Reputation: 614
The record.image_1920
is already Base64 encoded and you have to decode it. So try base64.b64decode(record.image_1920)
instead of base64.b64encode(record.image_1920)
.
Upvotes: 0