![](/img/trans.png)
[英]Issue with 'google.cloud.storage'. module has no attribute 'Client'
[英]Is it possible to use x-goog-if-generation-match in google.cloud.storage python client?
我正在使用 google.cloud.storage Python 库从我的 App Engine 灵活应用程序将文件存储在 Google Cloud Storage 中。 我想 x-goog-if-generation-match header 以防止覆盖较新的版本,但找不到将其传递给库的方法。
是否可以使用 google.cloud.storage Python 库进行 blob 生成检查?
截至今日,google cloud python 客户端支持 API 中的生成和元生成,包括Blob.upload_from_string
:
https://googleapis.dev/python/storage/latest/generation_metageneration.html#conditional-parameters
使用 if_generation_match
将 if_generation_match 参数传递给检索 blob 资源(例如,Blob.reload)或修改 blob(例如,Blob.update)的方法,使操作以 blob 的当前代是否与给定值匹配为条件。 作为一种特殊情况,将 0 作为
if_generation_match
的值传递会使操作仅在没有 blob 的实时版本时才会成功。
AFAIK x-goog-if-generation-match
标头仅在XML API中可用。
google.cloud.storage
库不允许直接访问请求标头。 在某些情况下,支持访问,但是通过专用属性,在google.cloud.storage.blob.Blob
,我看不到任何等效于x-goog-if-generation-match
的内容。
我确实看到了用于检索对象/ blob的生成和元生成的方法(但这些方法不等同于x-goog-if-generation-match
):
代
检索对象的生成。
请参阅https://cloud.google.com/storage/docs/json_api/v1/objects
返回类型:int或
NoneType
返回:blob的生成;如果尚未从服务器加载blob的资源,则返回None
。
和
metageneration
检索对象的元生成。
请参阅https://cloud.google.com/storage/docs/json_api/v1/objects
返回类型:int或
NoneType
返回:Blob的元生成;如果尚未从服务器加载Blob的资源,则返回None
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.