VideosMy ProjectsProgramming BlogGallery
  1. Home
  2. Blog
  3. Enable the caching of Images in Google Cloud Storage Buckets
Programming Blog

Atom/RSS Feed

google

Enable the caching of Images in Google Cloud Storage Buckets

google

To enable the caching of images in Google Cloud Storage buckets you need to set the file or bucket to public and set the Cache-Control attribute.

Setting the Bucket to public

  1. Open the Cloud Storage Browser
  2. Turn on Bucket Only Permissions

    To turn this on click the settings for the bucket and select Edit Bucket permissions

Setting the Cache-Control Attribute

When you are uploading images to the bucket ensure you include the attribute 'Cache-Control': 'public,max-age=<some time>' in the header. I use 36000 for my <some time> value. `

An example upload Post request:

{
   "method": "POST",//curl -X POST
   "headers": {//curl -H "Authorization: Bearer [OAUTH2_TOKEN]"
   "Cache-Control": "public,max-age=36000",
   "Authorization": "Bearer xxx"            
}
Join my mailing list