How to serve Google Cloud Storage images?

懵懂的女人 提交于 2019-11-28 09:04:55

问题


I want google.appengine.ext.blobstore and google.appengine.api.images to work outside of App Engine. Do these modules require App Engine in order to work? I want to create public but not guessable URLs of my images on Google Cloud Storage and serve them via Django.

I read that this is done with google.appengine.ext.blobstore.create_gs_key() and google.appengine.api.images.get_serving_url(). This is what I have so far:

from google.appengine.api import images
from google.appengine.ext import blobstore

bucketname = 'mybucket'

gcs_object_name = '/gs/mybucket/vincent-van-gogh/the-starry-night.jpg'
blob_key = blobstore.create_gs_key(gcs_object_name)
image_url = images.get_serving_url(blob_key)

And image_url is supposed to be a public but not guessable URL of my image. If I run this code, the error is

AssertionError: No api proxy found for service "blobstore"

This suggests blobstore needs a proxy, aka App Engine, in order to work its magic. Can App Engine modules work outside of App Engine? The docs say the above is a powerful way to serve images because I can generate a URL for each image and also resize the image dynamically.

Will this strategy work or is there a better way to serve images from Google Cloud Storage with Django?


回答1:


The blobstore and images APIs are available only within the App Engine runtime environment. To run them inside compute engine you can:

  • Run them inside Managed VMs (the GAE runtime environment on GCE)

  • Run them on your own infrastructure or GCE using a GAE API emulator (such as AppScale)

  • Use public APIs (such as Google Cloud Storage) instead

Some App Engine services (such as Datastore) now also expose public APIs that you can use from GCE.



来源:https://stackoverflow.com/questions/26987062/how-to-serve-google-cloud-storage-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!