Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Cache-Control on Google Cloud Storage bucket

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.

like image 731
Max Nilsson Avatar asked Aug 20 '14 13:08

Max Nilsson


People also ask

How can you control the access to Cloud Storage bucket?

Using IAM permissions with ACLs Cloud Storage offers two systems for granting users access your buckets and objects: IAM and Access Control Lists (ACLs). These systems act in parallel - in order for a user to access a Cloud Storage resource, only one of the systems needs to grant that user permission.

Which command line tool works with Google Cloud Storage buckets?

gsutil is a Python application that lets you access Cloud Storage from the command line. You can use gsutil to do a wide range of bucket and object management tasks, including: Creating and deleting buckets. Uploading, downloading, and deleting objects.


1 Answers

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.

like image 163
Mike Schwartz Avatar answered Oct 17 '22 00:10

Mike Schwartz