Google cloud storage Google存储Python ACL Udate不工作
我已经上传了一个图像文件到我的谷歌存储桶Google cloud storage Google存储Python ACL Udate不工作,google-cloud-storage,google-cloud-python,Google Cloud Storage,Google Cloud Python,我已经上传了一个图像文件到我的谷歌存储桶 #Block 1 #Storing the local file inside the bucket blob_response = bucket.blob(cloud_path) blob_response.upload_from_filename(local_path, content_type='image/png') 文件上传得很好。我验证bucket中的文件。 上传文件后,我将尝试使用相同的方法更新文件的acl,以便公开
#Block 1
#Storing the local file inside the bucket
blob_response = bucket.blob(cloud_path)
blob_response.upload_from_filename(local_path, content_type='image/png')
文件上传得很好。我验证bucket中的文件。
上传文件后,我将尝试使用相同的方法更新文件的acl,以便公开访问,如下所示:
#Block 2
blob_file = storage.Blob(bucket=bucket20, name=path_in_bucket)
acl = blob_file.acl
acl.all().grant_read()
acl.save()
这不会使文件公开
奇怪的是,在我运行上述上传方法之后,如果我只调用#Block 2代码。分别在jupyter笔记本中;它工作正常,文件可以公开获取
我试过:
- 上传代码后,检查bucket中是否存在blob文件
- 上传后引入5秒延迟
非常感谢您的帮助。如果您要将上载的文件从
upload\u from\u filename()
更改为public,您可以重新使用上载的blob。此外,请在更改权限之前添加acl的重新加载。这一切都是使用GCP AI平台在Jupyter笔记本的1个区块内完成的
# Block 1
bucket_name = "your-bucket"
destination_blob_name = "test.txt"
source_file_name = "/home/jupyter/test.txt"
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print(blob) #prints the bucket, file uploded
blob.acl.reload() # reload the ACL of the blob
acl = blob.acl
acl.all().grant_read()
acl.save()
for entry in acl:
print("{}: {}".format(entry["role"], entry["entity"]))
输出:
非常感谢,它解决了我的问题。我能够重用blob对象来更新acl权限。谢谢