您如何在Google云端存储中将许多文件设为私有? [英] How do you make many files private in Google Cloud Storage?

查看:52
本文介绍了您如何在Google云端存储中将许多文件设为私有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了很多研究,无法为此找到解决方案.这是我用来在GCP中公开所有文件的代码:

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()

上述方法有效,但是当我编写blob.make_private()使所有文件变为私有时,出现错误:AttributeError:'Blob'对象没有属性'make_private'

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'

在此链接上:

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

我既可以找到make_public()也可以找到make_private(),但只有make_public()有效.

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

推荐答案

make_private 已添加到

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.

尽管如此,如果您不能升级(假设您的开发环境已绑定"到该版本的库),我将在一个开发环境(版本1.8.0)中使用另一个版本对其进行测试.,如果您遵循 make_private 并在代码中执行这两行,即可正常工作.因此,像这样:

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)

这篇关于您如何在Google云端存储中将许多文件设为私有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆