如何提供Google Cloud Storage图片? [英] How to serve Google Cloud Storage images?

查看:233
本文介绍了如何提供Google Cloud Storage图片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要 google.appengine.ext.blobstore google.appengine.api.images 在App Engine。这些模块需要App Engine才能工作吗?我想在Google云端存储上创建我的图片的公开但不可猜测的网址,并通过Django进行投放。



我读到这是用 google.appengine.ext.blobstore.create_gs_key() google.appengine.api.images.get_serving_url()。这是我到目前为止:

  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)

和image_url应该是我的形象的公开但不可猜测的URL。如果我运行这个代码,错误是

  AssertionError:没有api代理服务找到blobstore

这表明blobstore需要一个代理服务器,也就是App Engine,以便工作。 App Engine模块可以在App Engine之外工作吗?文档说上述是提供图像的强大方法,因为我可以为每个图像生成一个URL,并动态调整图像大小。



此策略是否有效,或者是否有更好的方式来使用Django从Google Cloud Storage中提供图像?

解决方案

blobstore和图像API仅在App Engine运行时环境中可用。要在计算引擎中运行它们,您可以:




  • 托管虚拟机(GCE上的GAE运行时环境)


  • 运行使用GAE API模拟器(例如 AppScale )在自己的基础设施或GCE上使用它们。


  • 而不是使用公共API(如Google Cloud Storage)




App Engine服务(例如数据存储区)现在还会公开您可以从GCE使用的公共API。 / p>

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?

解决方案

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.

这篇关于如何提供Google Cloud Storage图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆