Set Cache-Control on Google Cloud Storage bucket

5 views
Skip to first unread message

Max Nilsson via StackOverflow

unread,
Aug 20, 2014, 9:51:21 AM8/20/14
to google-appengin...@googlegroups.com

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.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/25406410/set-cache-control-on-google-cloud-storage-bucket

Mike Schwartz via StackOverflow

unread,
Aug 20, 2014, 10:31:23 AM8/20/14
to google-appengin...@googlegroups.com

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.



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/25406410/set-cache-control-on-google-cloud-storage-bucket/25407394#25407394

Mike Schwartz via StackOverflow

unread,
Aug 20, 2014, 11:26:25 AM8/20/14
to google-appengin...@googlegroups.com

Mike Schwartz via StackOverflow

unread,
Aug 23, 2014, 12:39:55 PM8/23/14
to google-appengin...@googlegroups.com

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

...



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/25406410/set-cache-control-on-google-cloud-storage-bucket/25464091#25464091
Reply all
Reply to author
Forward
0 new messages