Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I read zip files from Google Storage in App Engine?

An application creates a zip file and stores it to Google Storage. I am working on the web server side which is responsible for grabbing the zip file extract the contents etc. The web service is written in Python App Engine. So far I have set the credentials and by following the tutorials I am able to list buckets contents. Although I am able to read the metadata and file information I am not able to get the contents to zip file module. Following this guide I have ended up in that spot which is not working:

uri = boto.storage_uri(BUCKET_NAME, GOOGLE_STORAGE)
objs = uri.get_bucket()
files = []
for obj in objs:
  object_contents = StringIO.StringIO()
  if obj.get_key():
    obj.get_file(object_contents)
    my_zip = zipfile.ZipFile(object_contents)
    object_contents.close()
    files.append(my_zip)
print len(files)  

I am getting: BadZipfile: File is not a zip file

How can I read the content properly?

like image 652
topless Avatar asked Dec 22 '25 14:12

topless


1 Answers

There's now an API that lets you manipulate objects in Google Storage directly. Using that, you can get a file-like object for the zipfile, and simply pass that to the zipfile module.

like image 187
Nick Johnson Avatar answered Dec 24 '25 03:12

Nick Johnson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!