Working With Object Metadata
Overview Of Metadata
Objects can have associated metadata, which control aspects of how
GET requests are handled, including
Content-Encoding. In addition,
you can set custom
key:value metadata for use by your applications.
For a discussion of specific metadata properties, see the
metadata concept page.
There are two ways to set metadata on objects:
At upload time you can specify one or more metadata properties to associate with objects, using the
gsutil -hoption. For example, the following command would cause gsutil to set the
Cache-Controlfor each of the files being uploaded from a local directory named
gsutil -h "Content-Type:text/html" \ -h "Cache-Control:public, max-age=3600" cp -r images \ gs://bucket/images
Note that -h is an option on the gsutil command, not the cp sub-command.
You can set or remove metadata fields from already uploaded objects using the
gsutil setmetacommand. See gsutil help setmeta.
Settable Fields; Field Values
You can't set some metadata fields, such as
fields you can set are:
- Custom metadata
Field names are case-insensitive.
All fields and their values must consist only of ASCII characters, with the
exception of values for
x-goog-meta- fields, which may contain arbitrary
Unicode values. Note that when setting metadata using the XML API, which sends
custom metadata as HTTP headers, Unicode characters are encoded using
UTF-8, then url-encoded to ASCII. For example:
gsutil setmeta -h "x-goog-meta-foo: ã" gs://bucket/object
stores the custom metadata key-value pair of
ls -L using the JSON API to list the object's metadata
ls -L using the XML API url-decodes this
value automatically, printing the character
Viewing Currently Set Metadata
You can see what metadata is currently set on an object by using:
gsutil ls -L gs://the_bucket/the_object