Download multiple file from Google cloud storage using Python

后端 未结 2 991
日久生厌
日久生厌 2021-01-12 20:02

I am trying to download multiple files from the Google cloud storage folder. I am able to download the single file but unable to download multiple files. I took this referen

2条回答
  •  自闭症患者
    2021-01-12 20:19

    After some trial, I solved this and couldn't stop myself from posting here as well.

    bucket_name = 'mybucket'
    folder='/projects/bigquery/download/shakespeare/'
    delimiter='/'
    file = 'shakespeare'
    
    # Retrieve all blobs with a prefix matching the file.
    bucket=storage_client.get_bucket(bucket_name)
    # List blobs iterate in folder 
    blobs=bucket.list_blobs(prefix=file, delimiter=delimiter) # Excluding folder inside bucket
    for blob in blobs:
       print(blob.name)
       destination_uri = '{}/{}'.format(folder, blob.name) 
       blob.download_to_filename(destination_uri)
    

提交回复
热议问题