0
votes

I'm using Google Cloud Storage for media. My website is stored elsewhere. I just want to display an image on my website without make this image public. I tried to display this image like this:

  • create API key for browser limited to my website (API key for http://*.example.com)
  • display image on this website <img src="https://www.googleapis.com/storage/v1/b/MY_BUKET/o/MY_MEDIA.jpg?key=MY_KEY" />
  • I can see in chrome console : ... "code": 401, "message": "Login Required" ...

I don't understand what I've missed, if I read the doc from google I'm lost: I just want to display an image with low security (but not public), not manage my media from my PHP app.

I can use google-api-php-client (my website is in PHP), but I don't know if I have something to do with this to make it work. I don't know where to start...

Thanks ! (I hope it's clear enough)

EDIT: I did not found any simple code example to render a private media in HTML using google-api-php-client; I'm lost

2

2 Answers

2
votes

The "key=" parameter doesn't assign any sort of permissions. It's a less secure identifier that is used to tell Google which project should be billed for this otherwise-anonymous, incoming call. It won't get you access to objects that aren't publicly available.

The only way you could embed a non-public image into your web page would be to generate a signed URL when the HTML page is requested. See https://cloud.google.com/storage/docs/accesscontrol#Signed-URLs for instructions on generating them.

1
votes

If your app is hosted on app engine then you can use the CloudStorageTools::serve() function to return the image as the result of a HTTP request and put in any access control you want.