mwest
mwest

Reputation: 11

GCS API function to get full URL for an image?

I have some images stored in Google Cloud Storage and I want to display them in a Google Sheets spreadsheet. The image urls I have are of the form:

https://storage.cloud.google.com/bucket-name/image-name

If I try to put this into the image() formula in Sheets it does not properly display the image. When following one of these links, it redirects to the image with a URL of the form:

([A-Za-z]\d)*-apidata.googleusercontent.com/download/storage/v1/b/bucket-name/o/object-name?qk=([A-Za-z]\d)*

Is there a GCS API function or Sheets formula that allows me to get this URL from the first one?

Upvotes: 0

Views: 811

Answers (1)

Nahuel Varela
Nahuel Varela

Reputation: 1040

You are receiving the ([A-Za-z]\d)*-apidata.googleusercontent.com/download/storage/v1/b/bucket-name/o/object-name?qk=([A-Za-z]\d)* link because you are trying to access a private image.

When you copy the link of the private object and you paste it on the browser, Google checks your credentials. If the account you are using has enough permissions to view the object, then it redirects you to the api.data link.

You can test this by copying the link of the object on the Cloud Console and then pasting it on incognito mode. You will see that it will prompt you for an account. But, if you paste the api.data link on incognito, it will still give you the object.

The easiest solution will be to define the image as Public and then copying the Public URL on the sheets page. It will be something like:

storage.googleapis.com/bucket/image.jpeg

Upvotes: 1

Related Questions