تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
3771 أدوات العرض

I need to process zip file. What I am doing is, in wizard, I created a field of type Binary like below

zip_file = fields.Binary("upload zip")

Now I need to use zip file uploaded in this file in my function.

for example.

from zipfile import ZipFile

my_zip_file = ZipFile(self.zip_file)

I am getting error (bytes object has no attribute seek)

I also tried

my_zip_file = ZipFile(io.BytesIO(self.zip_file))

I also tried

my_zip_file = ZipFile(io.BytesIO(self.zip_file).get_value())

Every time I get some error.

My question is:

How to convert this binary field as file like object?

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

I solved it.

Odoo fields.Binary data is in base64 encoding. We need to decode it before using it in io.BytesIO

for example
import base64
b64_data = base64.decodebytes(self.zip_file)
buffer= io.BytesIO(b64_data)
zip_data = ZipFile(buffer)

I hope that It may help someone else.


الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
1
سبتمبر 23
6890
1
فبراير 24
2832
0
يناير 22
2311
1
يونيو 20
3310
0
يوليو 19
3841