可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have a bucket with public images that are frequently updated and would like to disable the default cache duration of 3600. (E.g. "Cache-Control:private, max-age=0, no-transform")
Can the Cache-Control be set on a file while uploading it with PHP?
Is there a way to set the default Cache-Control for all future files in the bucket (like with ACL that all files are public)?
Right now I can only set it Cache-Control with gsutil and only for files currently on storage.
回答1:
You can set the Cache-Control while uploading an object - I suggest you use gsutil -D to see an example of the request it generates to do this, and then translate that to PHP:
gsutil -D -h Cache-Control:"Cache-Control:private, max-age=0, no-transform" \ cp file gs://your-bucket/file
There's no way to set a default Cache-Control for the bucket.
回答2:
Max: What's the typo you're referring to? When I run the command it works, and I see the specified Cache-Control in the debug output:
% gsutil -D -h Cache-Control:"Cache-Control:private, max-age=0, no-transform" cp file gs://my-bucket/file
...
INFO 0823 10:31:19.517297 base_api.py] Making http POST to https://www.googleapis.com/upload/storage/v1/b/my-bucket/o?fields=generation%2Ccrc32c%2Cmd5Hash%2Csize&alt=json&prettyPrint=True&uploadType=multipart INFO 0823 10:31:19.517704 base_api.py] Headers: {'accept': 'application/json', 'accept-encoding': 'gzip, deflate', 'content-length': '444', 'content-type': "multipart/related; boundary='===============6935917235018049421=='", 'user-agent': 'apitools gsutil/4.5 (darwin)'} INFO 0823 10:31:19.517773 base_api.py] Body: --===============6935917235018049421== Content-Type: application/json MIME-Version: 1.0
{"cacheControl": "Cache-Control:private, max-age=0, no-transform", "bucket": "my-bucket", "contentType": "text/x-c++", "name": "file", "contentLanguage": "en"} --===============6935917235018049421== Content-Type: text/x-c++ MIME-Version: 1.0 Content-Transfer-Encoding: binary
...