Can I set a folder or bucket-level "cacheControl" setting on a Firebase / Google Cloud Storage bucket?

Viewed 286

Instead of setting it for each uploaded file (images, for example), can I configure the bucket in some way that I can set a folder-level or a bucket-level rule for the cacheControl header?

> myBucket     // SOMETHING LIKE: myBucket.metadada = { "cacheControl: "public,max-age=31536000"}
  > folder1    // OR MAYBE: myBucket.folder1.metadada = { "cacheControl: "public,max-age=31536000"}
    image1.jpg  // INSTEAD OF SETTING IT FOR EVERY IMAGE FILE
    image2.jpg
  > folder2
    image3.jpg
    image4.jpg

Or is this a per-file configuration only?

1 Answers

As of now setting a rule is not supported by Cloud Storage. Although. you may edit the metadata of all objects inside a bucket or a folder, eg Cache-Control with the gsutil setmeta command.

To edit the metadata of all existing objects inside a bucket you may define as the bucket as a target:

gsutil setmeta -r -h "Cache-control:public, max-age=300" gs://bucket_name

In your case, you may upload all the files in a bucket or a folder and then use the above command to set Cache-Control to all the necessary objects.

Source

Related