Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch upload to google cloud using python

I am trying to upload multiple files at once using the google cloud python api, and am having trouble with it. Below is my code:

client = storage.Client.from_service_account_json("path_to_json")
bucket = client.get_bucket(bucket_name)
with client.batch():
    for i in range(10):
        try:
            blob = bucket.blob("my_blob")
            blob.upload_from_filename("path_to_file",content_type="image/jpeg")
    except Exception as e:
        raise e

However, this is telling me that there are no deferred requests to make. I have tried doing it without client.batch() and it works but is too slow. I was wondering if anyone has ever encountered this.

Thanks

like image 480
Oliver Spohngellert Avatar asked Oct 17 '22 23:10

Oliver Spohngellert


1 Answers

According to this issue, the back-end API doesn't support batching "media" operations

like image 107
Dominic Cabral Avatar answered Nov 11 '22 19:11

Dominic Cabral