setmeta - Set metadata on already uploaded objects
Synopsis
gsutil setmeta -h [header:value|header] ... url...
Description
The gsutil setmeta command allows you to set or remove the metadata on one or more objects. It takes one or more header arguments followed by one or more URLs, where each header argument is in one of two forms:
If you specify
header:value
, it sets the provided value for the given header on all applicable objects.If you specify
header
(with no value), it removes the given header from all applicable objects.
For example, the following command sets the Content-Type
and
Cache-Control
headers while also removing the Content-Disposition
header on the specified objects:
gsutil setmeta -h "Content-Type:text/html" \
-h "Cache-Control:public, max-age=3600" \
-h "Content-Disposition" gs://bucket/*.html
If you have a large number of objects to update you might want to use the gsutil -m option, to perform a parallel (multi-threaded/multi-processing) update:
gsutil -m setmeta -h "Content-Type:text/html" \
-h "Cache-Control:public, max-age=3600" \
-h "Content-Disposition" gs://bucket/*.html
You can also use the setmeta command to set custom metadata on an object:
gsutil setmeta -h "x-goog-meta-icecreamflavor:vanilla" gs://bucket/object
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.
See gsutil help metadata for details about how you can set metadata while uploading objects, what metadata fields can be set and the meaning of these fields, use of custom metadata, and how to view currently set metadata.
gsutil setmeta -h "Content-Type:text/html" \
-h "Cache-Control:private, max-age=0, no-transform" gs://bucket/*.html
The setmeta command reads each object's current generation and metageneration
and uses those as preconditions unless they are otherwise specified by
top-level arguments. For example, the following command sets the custom
metadata icecreamflavor:vanilla
if the current live object has a
metageneration of 2:
gsutil -h "x-goog-if-metageneration-match:2" setmeta
-h "x-goog-meta-icecreamflavor:vanilla"
Options
- -h
Specifies a header:value to be added, or header to be removed, from each named object.