Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Side by Side Diff: third_party/gsutil/gslib/addlhelp/metadata.py

Issue 10199002: Upgrade gsutil to 3.4 (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « third_party/gsutil/gslib/addlhelp/dev.py ('k') | third_party/gsutil/gslib/addlhelp/naming.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2012 Google Inc.
2 #
3 # 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 obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from gslib.help_provider import HELP_NAME
16 from gslib.help_provider import HELP_NAME_ALIASES
17 from gslib.help_provider import HELP_ONE_LINE_SUMMARY
18 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
23 _detailed_help_text = ("""
24 <B>CONTENT TYPE</B>
25 Objects can have associated metadata. The most common use is setting
26 the Content-Type (also known as MIME type) for an object, which allows
27 browsers to render the object properly. gsutil sets the Content-Type
28 automatically at upload time, based on each file's name and/or content. For
29 example, uploading files with names ending in .txt will set Content-Type
30 to text/plain. If you're running gsutil on Linux or MacOS and would prefer
31 to have content type set based on naming plus content examination, see the
32 use_magicfile configuration variable in the gsutil/boto configuration file
33 (See also "gsutil help config"). In general, using use_magicfile is more
34 robust and configurable, but is not available on Windows.
35
36 You can override the above Content-Type setting procedure by specifying a
37 Content-Type header on the gsutil command line. For example, this command
38 would cause gsutil to set a Content-Type of "image/jpg" for all the files
39 being uploaded:
40
41 gsutil -h 'Content-Type:image/jpg' cp -r images gs://bucket/images
42
43 Note that -h is an option on the gsutil command, not the cp sub-command.
44
45 You can also completely suppress content type detection in gsutil, by
46 specifying an empty string on the Content-Type header:
47
48 gsutil -h 'Content-Type:' cp -r images gs://bucket/images
49
50 In this case, the Google Cloud Storage service will attempt to detect
51 the content type. In general this approach will work better than using
52 filename extension-based content detection in gsutil, because the list of
53 filename extensions is kept more current in the server-side content detection
54 system than in the Python library upon which gsutil content type detection
55 depends. (For example, at the time of writing this, the filename extension
56 ".webp" was recognized by the server-side content detection system, but
57 not by gsutil.)
58
59 <B>CACHE-CONTROL</B>
60 Another commonly set piece of metadata is Cache-Control, which allows
61 you to control whether and for how long browser and Internet caches are
62 allowed to cache your objects. Cache-Control only applies to objects with
63 a public-read ACL. Non-public data are not cacheable.
64
65 Here's an example of uploading an object set to allow caching:
66
67 gsutil -h "Cache-Control:public,max-age=3600" \\
68 cp -a public-read -r html gs://bucket/html
69
70 This command would upload all files in the html directory (and subdirectories)
71 and make them publicly readable and cacheable, with cache expiration of
72 one hour.
73
74 Note that if you allow caching, at download time you may see older versions
75 of objects after uploading a newer replacement object. Note also that because
76 objects can be cached at various places on the Internet there is no way to
77 force a cached object to expire globally (unlike the way you can force your
78 browser to refresh its cache).
79
80
81 <B>CONTENT-ENCODING</B>
82 You could specify Content-Encoding to indicate that an object is compressed,
83 using a command like:
84
85 gsutil -h "Content-Encoding:gzip" cp *.gz gs://bucket/compressed
86
87 Note that Google Cloud Storage does not compress or decompress
88 objects. If you use this header to specify a compression type or
89 compression algorithm (for example, deflate), Google Cloud Storage
90 preserves the header but does not compress or decompress the object.
91
92 Note also that if you are uploading a large file with compressible content
93 (such as a .js, .css, or .html file), an easier way is available: see the
94 -z option in "gsutil help cp".
95
96
97 <B>CONTENT-DISPOSITION</B>
98 You can set Content-Disposition on your objects, to specify presentation
99 information about the data being transmitted. Here's an example:
100
101 gsutil -h 'Content-Disposition:attachment; filename=filename.ext' \\
102 cp -r attachments gs://bucket/attachments
103
104 See http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1
105 for details about the meaning of Content-Disposition.
106
107
108 <B>CUSTOM METADATA</B>
109 You can add your own custom metadata (e.g,. for use by your application)
110 to an object by setting a header that starts with "x-goog-meta", for example:
111
112 gsutil -h x-goog-meta-reviewer:jane cp mycode.java gs://bucket/reviews
113
114 Note that custom headers and their associated values must contain only
115 printable US-ASCII characters. If you want to store other data (such as
116 binary values or Unicode) you need to encode them as ASCII.
117
118
119 <B>VIEWING OBJECT METADATA</B>
120 You can view the metadata on an object using the gsutil ls -L command:
121
122 gsutil ls -L gs://bucket/images/*
123 """)
124
125
126
127 class CommandOptions(HelpProvider):
128 """Additional help about object metadata."""
129
130 help_spec = {
131 # Name of command or auxiliary help info for which this help applies.
132 HELP_NAME : 'metadata',
133 # List of help name aliases.
134 HELP_NAME_ALIASES : ['content type', 'mime type', 'mime', 'type'],
135 # Type of help:
136 HELP_TYPE : HelpType.ADDITIONAL_HELP,
137 # One line summary of this help.
138 HELP_ONE_LINE_SUMMARY : 'Setting object metadata (Content-Type, etc.)',
139 # The full help text.
140 HELP_TEXT : _detailed_help_text,
141 }
OLDNEW
« no previous file with comments | « third_party/gsutil/gslib/addlhelp/dev.py ('k') | third_party/gsutil/gslib/addlhelp/naming.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698