3
votes

I have some objects in different path in one bucket of Google Cloud storage.

I want to download all files in single zip file.

I am using Python GCS JSON API.

2
how many files? and how big are they? - Gwyn Howell
Thanks, It is approximately 5mb. - user3932031

2 Answers

2
votes

This gcs_zip_dynamics() function shows you here how to zip GCS files.

To download you can use:

self.response.headers[b'Content-Type'] = b'multipart/x-zip'
self.response.headers[b'Content-Disposition'] = str('attachment; filename=<file_name>.zip'
self.response.write(gcs_data.gcs_read_blob(dyn))

The gcs_read_blob() function is also part of the Gist.

1
votes
  • Use the cloudstorage library to download the files.
  • Use the zipfile library to create your zip archive.
  • Add the downloaded files to the zip archive.
  • Serve your zip file to the client.

Great example here.