如何更改 Google Cloud Storage 中文件的主要元数据字段的元数据? 我想修改主要元数据字段,例如内容处置或内容编码。
我的设置:
google-cloud-storage 2.3.0.
Google Cloud SDK 359.0.0
app-engine-python 1.9.94
app-engine-python-extras 1.9.94
beta 2021.09.24
bq 2.0.71
cloud-datastore-emulator 2.1.0
core 2021.09.24
gsutil 5.2
但是,当我按照官方文档中提供的说明进行操作时(https://cloud.google.com/storage/docs/viewing-editing-metadata#storage-set-object-metadata-python),它只出现影响自定义元数据。
def _open_gcs_file_for_write(gcs_blob, mode='w', options=None, content_type=None):
""" Helper function to open a GCS file for writing. """
headers = {}
if options or content_type:
if options:
headers.update(options)
if content_type:
gcs_blob.content_type = content_type
gcs_blob.metadata = headers
gcs_blob.patch()
options = {
'cache-control': 'max-age=3600',
'content-disposition': 'inline; filename="example.txt',
'content-encoding': 'gzip'
}
调用_open_gcs_file_for_write后,在存储桶存储的Google云控制台中,我只看到更改的自定义元数据,而不是特定字段:
对象的可编辑固定键元数据字段在 Python 客户端库中被视为可变对象属性。您可以使用
_helpers.py中定义的
_patch_property(self, name, value)
方法来更新它们。要使用的属性名称在 blob.py. 中定义
进行更新后,您必须通过在 blob 上调用
patch()
来坚持下去。