Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
6 ตอบกลับ
17868 มุมมอง

Hi,

How can I read content of binary field in Odoo8.

I added a fileds.Binary in my model and can browse file in view but I can't read It content.  

Please to give an exemple about how to browse a file and read It content in Odoo8 ?

 

อวตาร
ละทิ้ง

could you please give more details, did you meant about reading values from text file?

คำตอบที่ดีที่สุด

hii Omar OUHARI ,

below code help to read content of file after browse. and file is my fields.binary field. hope so this will help you.

base64.encodestring(args.get('file').read())

อวตาร
ละทิ้ง

please can you help me i use a txt field and store it as binary but when i upload it i find this: ÓMuÓM4

@Drees could you please give more details, did you meant about reading values from text file?

คำตอบที่ดีที่สุด

Hello Omar,

I see that your post is from 2015, but I had the same problem in 2019  :)

However I found a solution and I'm sharing it for someone who is experiencing the same issue.

In Ir_http.py there is a method  called binary_content, which returns a binary field content and some other info. You can use it in any model or controller with the following import:

from odoo.addons.web.controllers.main import binary_content

* Tested on Odoo 11 Community version

Regards,

Lyubo.

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi, 

this is what worked for me:

with io.BytesIO(base64.b64decode(self.binary_field_name)) as f:
    # do stuff with the contents here as if it were a file    
Best regards,
David


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ก.ค. 20
27716
2
ธ.ค. 23
25348
1
มี.ค. 15
3411
0
มี.ค. 15
3912
1
มี.ค. 15
4144