In order to delete custom metadata with the gsutil setmeta command you'd simply need to provide a null value to the relevant key. E.g. if you have a custom metadata names key
with a value foo
running the following command should delete the custom metadata:
gsutil setmeta -h "x-goog-meta-key:" gs://[YOUR-BUCKET]/[YOUR-OBJECT]
Take into consideration that as advised on the link I shared above:
Custom metadata is always prefixed in gsutil with x-goog-meta-. This distinguishes it from standard request headers. Other tools that send and receive object metadata by using the request body do not use this prefix.
Additionally you can delete the metadata fairly easily by clicking on the trashcan symbol of the Edit Metadata option on the Cloud Console.
EDIT
The following script should remove the metadata using the Python Client Library:
from google.cloud import storage
bucket_name = "[YOUR-BUCKET-NAME]"
blob_name = "[YOUR-OBJECT-NAME]"
key = "[YOUR-CUSTOM-METADATA-KEY-NAME]" #e.g. if you have a Custom Metadata named "key" with a value "foo" just enter key
def remove_blob_metadata(bucket_name, blob_name, key):
storage_client = storage.Client()
bucket = storage_client.bucket(bucket_name)
blob = bucket.get_blob(blob_name)
if blob.metadata != None:
if key not in blob.metadata.keys():
print("Couldn't find that key under the Custom Metadata field for object {} in bucket {}".format(blob_name,bucket_name))
else:
d = blob.metadata
blob.metadata = None
blob.patch()
del d[key]
blob.metadata = d
blob.patch()
print("Removed "{}" key from Custom Metadata field for object {} in bucket {}".format(key,blob_name,bucket_name))
else:
print("Object {} in bucket {} doesn't have Custom Metadata".format(blob_name,bucket_name))
remove_blob_metadata(bucket_name, blob_name, key)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…