繁体   English   中英

是否可以在 google.cloud.storage python 客户端中使用 x-goog-if-generation-match?

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM