setmeta - Set metadata on already uploaded objects

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 will set the given header on all named objects.
  • if you specify header (with no value), it will remove the given header from all named objects.

For example, the following command would set the Content-Type and Cache-Control and remove the Content-Disposition 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

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.

NOTE: By default, publicly readable objects are served with a Cache-Control header allowing such objects to be cached for 3600 seconds. For more details about this default behavior see the CACHE-CONTROL section of gsutil help metadata. If you need to ensure that updates become visible immediately, you should set a Cache-Control header of "Cache-Control:private, max-age=0, no-transform" on such objects. You can do this with the command:

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:

gsutil -h "x-goog-if-metageneration-match:2" setmeta
  -h "x-goog-meta-icecreamflavor:vanilla"

will set the icecreamflavor:vanilla metadata if the current live object has a metageneration of 2.

Options

-h Specifies a header:value to be added, or header to be removed, from each named object.

Send feedback about...

Cloud Storage Documentation