跳至內容
選單
此問題已被標幟
3127 瀏覽次數

Hi, I try to encode a large file but the below method gives me an error:

with open("/tmp/pdf/pdffiles.zip", "rb") as f:

binary_file = f.read()

encoded = base64.b64encode(binary_file)


self.download_zip = encoded


I tried to encode it chunk buy chunk but the downloded file is damaged:


zipfile = open("/tmp/pdf/pdffiles.zip", "rb")

encoded = False

while True:

chunk = zipfile.read(8192) 

if not chunk:

break

if encoded:

encoded += base64.b64encode(chunk)

else:

encoded = base64.b64encode(chunk)

zipfile.close()

self.download_zip = encoded 


Any hint how can I handle with large binary files?

頭像
捨棄
相關帖文 回覆 瀏覽次數 活動
0
8月 20
3925
2
12月 23
14665
0
10月 23
33
3
10月 23
788
1
10月 23
569