I need to zip all files in a given Cloud Storage bucket. I've already tried several alternatives, but nothing works so far.
At the moment, I'm only able to retrieve the blobs in the bucket, but I also need to generate a zip file grouping all these files and white it in the bucket .
Could you please help me with this issue?
Here is the code so far:
from google.cloud import storage
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="file.json"
def zip_in_bucket(bucketname):
client = storage.Client()
bucket = client.get_bucket(bucketname)
object_generator = bucket.list_blobs()
for files in object_generator:
print(files.name)
Return:
file-1.csv
file-2.csv
file-3.csv
file-4.csv
file-5.csv
there are two variants of solving this problem, either you use the google cloud shell.
or you can do this using your python code. The thing is that you have to stream the files through your cloud function.