在Blobstore中存储静态图像

在Blobstore中存储静态图像

问题描述:

通常在app-engine上托管网站,我可以将所有图像文件放在一个静态目录中,例如img,然后在yaml文件中包含

Normally to host a website on app-engine, I can put all my image files in a static directory, say img, and then in the yaml file have

  • 网址:/img static_dir:img
  • url: /img static_dir: img

当图片要显示在我的网站本身中时,这种用法很有意义.

Such a usage makes sense when the images are for displaying in my website itself.

但是现在我有了一个端点api.就我而言,我需要在后端存储一些图像以供用户访问.与其将它们放在静态目录中,不如将它们放在blobstore中,并使用blob服务url为它们提供服务.有没有一种方法可以将映像部署到Blob存储区,然后获取提供的网址?

But now I have an endpoint api. For my case, I need to store some images in my backend for my users to access. Instead of putting them in static directory, I want to put them in the blobstore and use blob serving url to serve them. Is there a way to deploy images to the blobstore and then get the serving urls?

您可以实施一项任务,检查文件是否在blobstore中,如果没有,则将其上载到blobstore.然后,您可以在cron中运行此任务,也可以将其作为预热任务.

You could implement a task that checks if the files are in the blobstore or not, and if not, uploads them to the blobstore. Then you can run this task in cron or as a warmup task.

仍然,最好使用静态Web服务并从静态存储中提取HTTP中的静态文件.它的性能将比blobstore更好(实际上,它的性能比大多数静态Web托管要好得多),而且成本更低.

Still, it will be best for you to use the static web serving and pull the static files in HTTP from the static storage. It will perform much better than blobstore (in fact, it performs much better than most static web hosting), and will cost you less.