1

I have issue with Google Cloud Bucket. When I call my files at Google Cloud they come with the headers private and max-age=0 so there will no caching options.

I use console for setting meta-data option. I type:

gsutil -m setmeta -r "Cache-Control:public, max-age=3600" gs://bucket/folder*

but it does not work. What should I do? This is a horrible issue for me.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

1 Answers1

0

The gsutil command is link :

gsutil setmeta -h [header:value|header] ... url...

The following command worked for me:

gsutil -m setmeta -h "Cache-Control:public, max-age=3600" gs://destination/object

-h Specifies a header:value to be added, or header to be removed, from each named object.

You can use wildcards with command, for example all objects:

gsutil -m setmeta -h "Cache-Control:public, max-age=3600"  gs://YOUR_BUCKET/**/*

The metadata applies only to objects and I do not think you can apply a rule to bucket to apply for future objects.

marian.vladoi
  • 7,663
  • 1
  • 15
  • 29
  • Thank you for your response. This is working for each object. I did this with using this command for each object but I want to set this for whole bucket level and be sure to set this for future files. Did you know any method for this? – Muhammed Tüfekyapan Nov 10 '19 at 17:12
  • As explained in the answer, it is not possible to set that at bucket level. However, you can create a Cloud Function that sets the desired metadata once an object has been uploaded to your bucket. [This post](https://stackoverflow.com/a/51612857/9745709) shows you how – Pablo Almécija Rodríguez Nov 11 '19 at 12:02