| OLD | NEW |
| 1 # -*- coding: utf-8 -*- |
| 1 # Copyright 2012 Google Inc. All Rights Reserved. | 2 # Copyright 2012 Google Inc. All Rights Reserved. |
| 2 # | 3 # |
| 3 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
| 5 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
| 6 # | 7 # |
| 7 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 # | 9 # |
| 9 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
| 10 # distributed under the License is distributed on an "AS IS" BASIS, | 11 # distributed under the License is distributed on an "AS IS" BASIS, |
| 11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 # See the License for the specific language governing permissions and | 13 # See the License for the specific language governing permissions and |
| 13 # limitations under the License. | 14 # limitations under the License. |
| 15 """Additional help about object metadata.""" |
| 14 | 16 |
| 15 from gslib.help_provider import HELP_NAME | 17 from __future__ import absolute_import |
| 16 from gslib.help_provider import HELP_NAME_ALIASES | 18 |
| 17 from gslib.help_provider import HELP_ONE_LINE_SUMMARY | |
| 18 from gslib.help_provider import HelpProvider | 19 from gslib.help_provider import HelpProvider |
| 19 from gslib.help_provider import HELP_TEXT | |
| 20 from gslib.help_provider import HelpType | |
| 21 from gslib.help_provider import HELP_TYPE | |
| 22 | 20 |
| 23 _detailed_help_text = (""" | 21 _DETAILED_HELP_TEXT = (""" |
| 24 <B>OVERVIEW OF METADATA</B> | 22 <B>OVERVIEW OF METADATA</B> |
| 25 Objects can have associated metadata, which control aspects of how | 23 Objects can have associated metadata, which control aspects of how |
| 26 GET requests are handled, including Content-Type, Cache-Control, | 24 GET requests are handled, including Content-Type, Cache-Control, |
| 27 Content-Disposition, and Content-Encoding (discussed in more detail in | 25 Content-Disposition, and Content-Encoding (discussed in more detail in |
| 28 the subsections below). In addition, you can set custom metadata that | 26 the subsections below). In addition, you can set custom metadata that |
| 29 can be used by applications (e.g., tagging that particular objects possess | 27 can be used by applications (e.g., tagging that particular objects possess |
| 30 some property). | 28 some property). |
| 31 | 29 |
| 32 There are two ways to set metadata on objects: | 30 There are two ways to set metadata on objects: |
| 33 | 31 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 44 | 42 |
| 45 - You can set or remove metadata fields from already uploaded objects using | 43 - You can set or remove metadata fields from already uploaded objects using |
| 46 the gsutil setmeta command. See "gsutil help setmeta". | 44 the gsutil setmeta command. See "gsutil help setmeta". |
| 47 | 45 |
| 48 More details about specific pieces of metadata are discussed below. | 46 More details about specific pieces of metadata are discussed below. |
| 49 | 47 |
| 50 | 48 |
| 51 <B>CONTENT TYPE</B> | 49 <B>CONTENT TYPE</B> |
| 52 The most commonly set metadata is Content-Type (also known as MIME type), | 50 The most commonly set metadata is Content-Type (also known as MIME type), |
| 53 which allows browsers to render the object properly. | 51 which allows browsers to render the object properly. |
| 54 gsutil sets the Content-Type | 52 gsutil sets the Content-Type automatically at upload time, based on each |
| 55 automatically at upload time, based on each filename extension. For | 53 filename extension. For example, uploading files with names ending in .txt |
| 56 example, uploading files with names ending in .txt will set Content-Type | 54 will set Content-Type to text/plain. If you're running gsutil on Linux or |
| 57 to text/plain. If you're running gsutil on Linux or MacOS and would prefer | 55 MacOS and would prefer to have content type set based on naming plus content |
| 58 to have content type set based on naming plus content examination, see the | 56 examination, see the use_magicfile configuration variable in the gsutil/boto |
| 59 use_magicfile configuration variable in the gsutil/boto configuration file | 57 configuration file (See also "gsutil help config"). In general, using |
| 60 (See also "gsutil help config"). In general, using use_magicfile is more | 58 use_magicfile is more robust and configurable, but is not available on |
| 61 robust and configurable, but is not available on Windows. | 59 Windows. |
| 62 | 60 |
| 63 If you specify a -h header when uploading content (like the example gsutil | 61 If you specify a Content-Type header with -h when uploading content (like the |
| 64 command given in the previous section), it overrides the Content-Type that | 62 example gsutil command given in the previous section), it overrides the |
| 65 would have been set based on filename extension or content. This can be | 63 Content-Type that would have been set based on filename extension or content. |
| 66 useful if the Content-Type detection algorithm doesn't work as desired | 64 This can be useful if the Content-Type detection algorithm doesn't work as |
| 67 for some of your files. | 65 desired for some of your files. |
| 68 | 66 |
| 69 You can also completely suppress content type detection in gsutil, by | 67 You can also completely suppress content type detection in gsutil, by |
| 70 specifying an empty string on the Content-Type header: | 68 specifying an empty string on the Content-Type header: |
| 71 | 69 |
| 72 gsutil -h 'Content-Type:' cp -r images gs://bucket/images | 70 gsutil -h 'Content-Type:' cp -r images gs://bucket/images |
| 73 | 71 |
| 74 In this case, the Google Cloud Storage service will attempt to detect | 72 In this case, the Google Cloud Storage service will not attempt to detect |
| 75 the content type. In general this approach will work better than using | 73 the content type. In general this approach will work better than using |
| 76 filename extension-based content detection in gsutil, because the list of | 74 filename extension-based content detection in gsutil, because the list of |
| 77 filename extensions is kept more current in the server-side content detection | 75 filename extensions is kept more current in the server-side content detection |
| 78 system than in the Python library upon which gsutil content type detection | 76 system than in the Python library upon which gsutil content type detection |
| 79 depends. (For example, at the time of writing this, the filename extension | 77 depends. (For example, at the time of writing this, the filename extension |
| 80 ".webp" was recognized by the server-side content detection system, but | 78 ".webp" was recognized by the server-side content detection system, but |
| 81 not by gsutil.) | 79 not by gsutil.) |
| 82 | 80 |
| 83 | 81 |
| 84 <B>CACHE-CONTROL</B> | 82 <B>CACHE-CONTROL</B> |
| (...skipping 12 matching lines...) Expand all Loading... |
| 97 one hour. | 95 one hour. |
| 98 | 96 |
| 99 Note that if you allow caching, at download time you may see older versions | 97 Note that if you allow caching, at download time you may see older versions |
| 100 of objects after uploading a newer replacement object. Note also that because | 98 of objects after uploading a newer replacement object. Note also that because |
| 101 objects can be cached at various places on the Internet there is no way to | 99 objects can be cached at various places on the Internet there is no way to |
| 102 force a cached object to expire globally (unlike the way you can force your | 100 force a cached object to expire globally (unlike the way you can force your |
| 103 browser to refresh its cache). | 101 browser to refresh its cache). |
| 104 | 102 |
| 105 Another use of the Cache-Control header is through the "no-transform" value, | 103 Another use of the Cache-Control header is through the "no-transform" value, |
| 106 which instructs Google Cloud Storage to not apply any content transformations | 104 which instructs Google Cloud Storage to not apply any content transformations |
| 107 based on specifics of a download request, such such as removing gzip | 105 based on specifics of a download request, such as removing gzip |
| 108 content-encoding for incompatible clients. | 106 content-encoding for incompatible clients. Note that this parameter is only |
| 107 respected by the XML API. The Google Cloud Storage JSON API respects only the |
| 108 no-cache and max-age Cache-Control parameters. |
| 109 | 109 |
| 110 | 110 |
| 111 <B>CONTENT-ENCODING</B> | 111 <B>CONTENT-ENCODING</B> |
| 112 You can specify a Content-Encoding to indicate that an object is compressed | 112 You can specify a Content-Encoding to indicate that an object is compressed |
| 113 (for example, with gzip compression) while maintaining its Content-Type. | 113 (for example, with gzip compression) while maintaining its Content-Type. |
| 114 You will need to ensure that the files have been compressed using the | 114 You will need to ensure that the files have been compressed using the |
| 115 specified Content-Encoding before using gsutil to upload them. Consider the | 115 specified Content-Encoding before using gsutil to upload them. Consider the |
| 116 following example for Linux: | 116 following example for Linux: |
| 117 | 117 |
| 118 echo "Highly compressible text" | gzip > foo.txt | 118 echo "Highly compressible text" | gzip > foo.txt |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 <B>SETTABLE FIELDS; FIELD VALUES</B> | 161 <B>SETTABLE FIELDS; FIELD VALUES</B> |
| 162 You can't set some metadata fields, such as ETag and Content-Length. The | 162 You can't set some metadata fields, such as ETag and Content-Length. The |
| 163 fields you can set are: | 163 fields you can set are: |
| 164 | 164 |
| 165 - Cache-Control | 165 - Cache-Control |
| 166 - Content-Disposition | 166 - Content-Disposition |
| 167 - Content-Encoding | 167 - Content-Encoding |
| 168 - Content-Language | 168 - Content-Language |
| 169 - Content-MD5 | 169 - Content-MD5 |
| 170 - Content-Type | 170 - Content-Type |
| 171 - Any field starting with X-GOOG-META- (i.e., custom metadata). | 171 - Any field starting with a matching Cloud Storage Provider |
| 172 prefix, such as x-goog-meta- (i.e., custom metadata). |
| 172 | 173 |
| 173 Header names are case-insensitive. | 174 Header names are case-insensitive. |
| 174 | 175 |
| 175 X-GOOG-META- fields can have data set to arbitrary Unicode values. All | 176 x-goog-meta- fields can have data set to arbitrary Unicode values. All |
| 176 other fields must have ASCII values. | 177 other fields must have ASCII values. |
| 177 | 178 |
| 178 | 179 |
| 179 <B>VIEWING CURRENTLY SET METADATA</B> | 180 <B>VIEWING CURRENTLY SET METADATA</B> |
| 180 You can see what metadata is currently set on an object by using: | 181 You can see what metadata is currently set on an object by using: |
| 181 | 182 |
| 182 gsutil ls -L gs://the_bucket/the_object | 183 gsutil ls -L gs://the_bucket/the_object |
| 183 """) | 184 """) |
| 184 | 185 |
| 185 | 186 |
| 186 class CommandOptions(HelpProvider): | 187 class CommandOptions(HelpProvider): |
| 187 """Additional help about object metadata.""" | 188 """Additional help about object metadata.""" |
| 188 | 189 |
| 189 help_spec = { | 190 # Help specification. See help_provider.py for documentation. |
| 190 # Name of command or auxiliary help info for which this help applies. | 191 help_spec = HelpProvider.HelpSpec( |
| 191 HELP_NAME : 'metadata', | 192 help_name='metadata', |
| 192 # List of help name aliases. | 193 help_name_aliases=[ |
| 193 HELP_NAME_ALIASES : ['cache-control', 'caching', 'content type', | 194 'cache-control', 'caching', 'content type', 'mime type', 'mime', |
| 194 'mime type', 'mime', 'type'], | 195 'type'], |
| 195 # Type of help: | 196 help_type='additional_help', |
| 196 HELP_TYPE : HelpType.ADDITIONAL_HELP, | 197 help_one_line_summary='Working With Object Metadata', |
| 197 # One line summary of this help. | 198 help_text=_DETAILED_HELP_TEXT, |
| 198 HELP_ONE_LINE_SUMMARY : 'Working With Object Metadata', | 199 subcommand_help_text={}, |
| 199 # The full help text. | 200 ) |
| 200 HELP_TEXT : _detailed_help_text, | |
| 201 } | |
| OLD | NEW |