How do you make many files private in Google Cloud Storage?

只谈情不闲聊 提交于 2021-01-27 18:30:29

问题


I have researched a lot and unable to come up with a solution for this. Here is the code i am using to make all the files public in GCP:

def make_blob_public(bucket_name, blob_name):
    """Makes a blob publicly accessible."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(blob_name)

blob.make_public()

The above method works but when i write blob.make_private() to make all files private i get the error: AttributeError: 'Blob' object has no attribute 'make_private'

At this link:

https://googlecloudplatform.github.io/google-cloud-python/latest/storage/blobs.html

i can find both make_public() and make_private() but only make_public() works.


回答1:


make_private was added in the 1.10 version of the Storage client library. Check which version are you using with pip list, as you must be using a different version, and upgrade if possible.

Nonetheless, if you can't upgrade (let's say that your development environment is 'tied' to this version of the library), I tested this with a different version that I have in one development environment (version 1.8.0) , and if you follow the source code for make_private and do those two lines in the code, it works. So, like this:

#blob.make_private() is basically:

blob.acl.all().revoke_read()
blob.acl.save(client=blob.client)


来源:https://stackoverflow.com/questions/51405256/how-do-you-make-many-files-private-in-google-cloud-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!