GCP - get full information about bucket

前端 未结 2 484
情深已故
情深已故 2020-12-19 16:31

I need to get the file information stored in Google Bucket. Information Like Filesize, Storage Class, Last Modified, Type. I searched for the google docs bu

2条回答
  •  清歌不尽
    2020-12-19 17:09

    Using the Cloud Storage client library, and checking at the docs for buckets, you can do this to get the Storage Class:

    from google.cloud import storage
    client = storage.Client()
    bucket = client.get_bucket('YOUR_BUCKET')
    print(bucket.storage_class)
    

    As for the size and last modified files (at least it's what I understood from your question), those belong to the files itself. You could iterate the list of blobs in your bucket and check that:

    for blob in bucket.list_blobs():
        print(blob.size)
        print(blob.updated)
    

提交回复
热议问题