Set Cache-Control on Google Cloud Storage bucket

匿名 (未验证) 提交于 2019-12-03 01:38:01

问题:

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

...



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!