mgshorta
mgshorta

Reputation: 43

Google Cloud Storage - Public object url e super slow updating

I have a bucket with READ permission to allUsers and it's working fine but the public url link https://storage.googleapis.com/example_bucket/example.png takes ages to update: if I change the image in storage for a different one with the same name, the bucket view shows the correct image as well as the not public image url https://storage.cloud.google.com/example_bucket/example.png however the public url shows the old image and it takes a long time to update. Could someone explain if this is normal or if I'm doing something wrong?

Upvotes: 4

Views: 3377

Answers (4)

Taha Malik
Taha Malik

Reputation: 2393

In our case we were updated using the google cloud storage console GUI. If someone is doing the same then the steps you need to follow are:

  1. upload the image to the bucket and overwrite previous one (it will remove the public access, if it had) (according to my observation) and click on the uploaded file e.g. 1.jpg in the image below

Cloud Storage Bucket

  1. You will see something like the following image. Click edit metadata, this should be done before adding public access

Object Details

  1. Add Cache Control header something like this

Object metadata

  1. make it public now, if the url is already cached, you can append some parameters like http://your.complete.url/1.jpg?abc=1 you can append any paramater as long as syntax is correct.

  2. Everytime you update the object these steps need to be followed

Upvotes: 2

Haha
Haha

Reputation: 458

I was coming across this same issue while serving up profile images for my users. I fixed this by chaining ?ignoreCache=1 onto the public url.

Upvotes: 4

Joss Baron
Joss Baron

Reputation: 1524

You can set the cache-control when you are uploading the object:

Using gsutil when

  1. Uploading

gsutil -D -h Cache-Control:"Cache-Control:private, max-age=0, no-transform" cp file gs://BUCKET/file

  1. Editing: gsutil set meta

gsutil setmeta -h Cache-Control:"Cache-Control:private, max-age=0, no-transform" gs://BUCKET/file

Or through the console:

enter image description here

Currently, there is no way to set a default cache-control for the bucket.

You might be interested in taking a look into this Viewing / Editing Metadata

Upvotes: 1

Mike Schwartz
Mike Schwartz

Reputation: 12145

Objects created with READ permission to allUsers by default are served with cache-control: public, max-age=3600. With this cache-control in place updates to the object could not be reflected at caches for an hour.

Upvotes: 4

Related Questions