0

I am uploading a zip(which further contains pdf files to be read) as multipart/form-data .

I am handling the upload as below:

file = request.FILES["zipfile"].read() #gives a byte object
bytes_io = io.BytesIO(file) # gives a IO stream object

What I intend to do is to read the pdf files inside the zip, but I am stuck as to how to proceed from here. I am confused, what do I do with either the bytes object from the request or the IO object after conversion.

Rahul
  • 115
  • 10

1 Answers1

0

Found the answer just after asking the question.

Simply use the zipfile package as below:

from zipfile import ZipFile
file = request.FILES["zipfile"].read()
bytes_io = io.BytesIO(file)
zipfile = ZipFile(bytes_io, 'r')

And then refer the docs for further operations on the zip file. Hope it helps!

Rahul
  • 115
  • 10