Viewing and editing object metadata

This page describes how to view and edit the metadata associated with objects
stored in Cloud Storage. For an overview of object metadata, see
Object Metadata.

This page does not cover viewing or editing Identity and Access Management
(IAM) policies or object Access Control Lists (ACLs), both of which control who
is allowed to access your data. See Using IAM Permissions and
Creating and Managing ACLs for guides to accomplishing these tasks.

gsutil

[METADATA_KEY] is the key for the metadata you want to set. For example,
Content-Type.

[METADATA_VALUE] is the value for the metadata you want to set. For
example, image/png.

[BUCKET_NAME] is the name of the bucket containing the object whose
metadata you want to edit. For example, my-bucket.

[OBJECT_NAME] is the name of the object whose metadata you want to edit.
For example, pets/dog.png.

If successful, the response looks like the following example:

Operation completed over 1 objects.

Note that if you are adding custom metadata with gsutil, you must prefix
your metadata key with x-goog-meta- for gsutil to recognize that this is a
custom metadata attribute, rather than a standard HTTP header. The metadata
key itself is not stored with the x-goog-meta- prefix. An example of
custom "[METADATA_KEY]:[METADATA_VALUE]" is "x-goog-meta-dogbreed:shibainu".

REST APIs

JSON API

Get an authorization access token from the
OAuth 2.0 Playground. Configure the playground to use your own OAuth credentials.

[OAUTH2_TOKEN] is the name of the access token you generated in Step 1.

[BUCKET_NAME] is the name of the bucket containing the object
whose metadata you want to edit. For example, my-bucket.

[OBJECT_NAME] is the name of the object whose metadata you want
to edit. For example, pets/dog.png.

Note that you can also change an object's metadata with an
UPDATE Object request. When using this method, any metadata
that is not explicitly specified in the request is removed from the
object's metadata.

XML API

When working with the XML API, metadata can only be set at the
time the object is written, such as when uploading, moving, or
overwriting the object. Follow instructions such as
uploading an object with the following guidelines:

Add -H "[METADATA_KEY]:[METADATA_VALUE]" to the request header
for each metadata value you are setting. For example, -H "Content-Type:image/png".

Prefix x-goog-meta- to any custom metadata values. An example of
custom "[METADATA_KEY]:[METADATA_VALUE]" is "x-goog-meta-dogbreed:shibainu".