Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
3140 Vizualizări

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?

Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
0
aug. 20
3935
2
dec. 23
14680
0
oct. 23
33
3
oct. 23
788
1
oct. 23
569