【问题标题】:How to serve google cloud storage image from local server?如何从本地服务器提供谷歌云存储图像?
【发布时间】:2015-02-20 02:04:02
【问题描述】:

使用最新的 GAE SDK (1.9.17),我遵循了使用 blobstore 和图像库提供谷歌云存储图像的所有说明,但在本地它给了我 500 错误。将应用程序部署到生产服务器,提供图像工作正常。但是,这非常烦人,因为我需要在本地开发,而且我的项目是图像密集型的。

这在生产中运行良好:

key = blobstore.create_gs_key('/gs/my_bucket/my_folder/my_image.jpg')
url = images.get_serving_url(key)

在生产环境中,服务 url 如下所示:

http://lh6.ggpht.com/ow6Z3PrYyLVdvRDc9cT9I3MB9ug...

在本地,url 看起来像:

http://0.0.0.0:8080/_ah/img/encoded_gs_file:Z2lmdF9p...

App Engine 错误日志显示:

错误 2014-12-21 23:12:35,256 blob_download.py:204] 找不到 带钥匙的斑点 编码_gs_file:Z2lmdF9p...

我做错了吗?文档说在 SDK 1.8 之后在本地提供图像应该可以正常工作。如果我不能让它工作,我唯一的解决方案是保留所有生产图像(许多 GB)在本地托管以进行开发。

【问题讨论】:

  • 你解决了吗?我也有同样的问题...

标签: google-app-engine google-cloud-storage blobstore


【解决方案1】:

请参阅this very good repo,其中解释了如何在 GCS 中保存文件,无论是在开发 SDK 中还是在生产中。

具体来说,对于您的问题:

   # image API supported formats
    if file_extension in ['jpeg', 'jpg', 'png', 'gif', 'bmp', 'tiff', 'ico']:
        # High-performance dynamic image serving
        self.serving_url = images.get_serving_url(self.blobkey, secure_url=True)
    elif os.environ['SERVER_SOFTWARE'].startswith('Development'):
        # GCS url: this SDK feature has not been documented yet !!!
        self.serving_url = '/_ah/gcs%s' % self.gcs_filename
    else:
        # GCS url: because of HTTPS we cannot use a cname redirect or use the use_blobstore option
        self.serving_url = 'https://storage.googleapis.com%s' % self.gcs_filename

感谢@voscausa

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 1970-01-01
    • 2013-10-19
    • 2021-09-20
    • 2019-06-17
    • 2019-04-16
    • 1970-01-01
    相关资源
    最近更新 更多