Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view an image stored in Google cloud storage bucket?

I have a bucket that has images stored in it , when I retrieve the image using the public URL of the image it downloads it in the browser instead of showing the image in the browser , how can I view the image instead of downloading it. I use the following URL for the uploaded image.

https://www.googleapis.com/download/storage/v1/b/image-downloader-bucket/o/a06266f6-6082-468e-92ca-f918a48533a8?generation=1455661996337000&alt=media

Can someone let me know how to create the right URL for viewing the image ?

like image 574
user1965449 Avatar asked Feb 16 '16 23:02

user1965449


2 Answers

If the object is publicly readable, you can view it directly at "https://storage.googleapis.com/BUCKET_NAME/OBJECT_NAME", which in your case would be https://storage.googleapis.com/image-downloader-bucket/a06266f6-6082-468e-92ca-f918a48533a8.

like image 124
Brandon Yarbrough Avatar answered Oct 17 '22 00:10

Brandon Yarbrough


My problem was that I wasn't setting the mimetype for the object. Without it, the browser didn't know it was an image, so it was downloading the file instead of displaying it in the browser window

Adding this did the trick:

const blobStream = blob.createWriteStream({
  metadata: {
    contentType: "image/jpeg"
  }
});
like image 12
Eric Avatar answered Oct 16 '22 23:10

Eric