setmeta - Set metadata on already uploaded objects
Synopsis
gsutil setmeta [-n] -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
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. 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
Operation Cost
This command uses four operations per URL (one to read the ACL, one to read the current metadata, one to set the new metadata, and one to set the ACL).
For cases where you want all objects to have the same ACL you can avoid half these operations by setting a default ACL on the bucket(s) containing the named objects, and using the setmeta -n option. See “help gsutil defacl”.
Options
-h | Specifies a header:value to be added, or header to be removed, from each named object. |
-n | Causes the operations for reading and writing the ACL to be skipped. This halves the number of operations performed per request, improving the speed and reducing the cost of performing the operations. This option makes sense for cases where you want all objects to have the same ACL, for which you have set a default ACL on the bucket(s) containing the objects. See “help gsutil defacl”. |