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

前端 未结 4 1447
无人及你
无人及你 2020-12-20 14:51

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

相关标签:
4条回答
  • 2020-12-20 15:09

    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"
      }
    });
    
    0 讨论(0)
  • 2020-12-20 15:28

    Similar to the @ehero response but for python, the point is using content_type blob attribute before uploading the file:

    from google.cloud import storage
    storage_client = storage.Client.from_service_account_json('your/path/to/service/credentials.json')
    bucket = storage_client.bucket('my-bucket-name')
    blob = bucket.blob('my/path/in/storage.jpg')
    blob.content_type = 'image/jpeg' # This one is the important
    blob.upload_from_file(file) # Also available upload_from_filename
    
    0 讨论(0)
  • 2020-12-20 15:32

    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.

    0 讨论(0)
  • Yes there is! You actually resize the image of your file stored in Google Cloud Storage thru the Images API. Have a look at this link:

    https://cloud.google.com/appengine/docs/java/images/

    0 讨论(0)
提交回复
热议问题