【问题标题】:Google Cloud Storage on Appengine Dev ServerAppengine 开发服务器上的谷歌云存储
【发布时间】:2013-12-08 02:48:16
【问题描述】:

最近在 Stackoverflow 上回复了一个类似的问题:Google Cloud Storage Client not working on dev appserver

解决方案是将 SDK 升级到 1.8.8 或使用没有错误的 GCS 客户端库的先前版本。

我目前使用的是 1.8.8 并尝试下载多个修订版,但 /_ah/gcs 无法为我加载。在用完大量后端实例后,试图了解 GCS 和应用引擎如何协同工作,如果我可以在本地服务器上进行测试,那就太好了!

当我访问 localhost:port/_ah/gcs 时,我收到 404 not found 错误。

请注意,安装库我所做的只是将代码拖放到我的应用程序文件夹中。我想知道我是否跳过了设置步骤?我无法在文档中找到答案!

谢谢!!

注意 为了澄清这是我使用 GCS 的第一周,所以我第一次尝试使用 dev_server 来托管它。

【问题讨论】:

  • 嘿,你有没有想过这个问题?我也被困在这个问题上。
  • 不,我已经将那部分处理移出 appengine —— 限制 + 无法在开发环境中进行测试正在扼杀我的开发时间!尽管如此,我们的大部分代码仍然使用 appengine,它很棒但很昂贵(我们也在努力降低成本并更有效地使用它)。
  • 与其他解决方案相比,例如heroku,Google Cloud 看起来像一团糟,而且记录得很糟糕!
  • 找到解决办法了吗?

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


【解决方案1】:

我能够在以下位置找到我写入本地存储桶的谷歌云存储文件:

    localhost:port/_ah/gcs/bucket_name/file_suffix

默认端口为8080,文件写入:/bucket_name/file_suffix

对于那些试图了解设置简单的 python GAE 应用程序和测试本地写入谷歌云存储的完整过程的人:

1。按照谷歌应用引擎“快速入门”:

https://cloud.google.com/appengine/docs/standard/python/quickstart

2。运行本地开发服务器:

    dev_appserver.py app.yaml 

3。如果使用 python,请遵循“App Engine 和 Google Cloud Storage 示例”:

https://cloud.google.com/appengine/docs/standard/python/googlecloudstorageclient/app-engine-cloud-storage-sample

如果您遇到“ImportError: No module named cloudstorage”,您需要创建一个名为 appengine_config.py 的文件

    touch appengine_config.py

并添加到它:

    from google.appengine.ext import vendor
    vendor.add('lib')

当使用 dev_appserver.py app.yaml 启动本地开发服务器时,GAE 会自动运行此脚本,GAE 需要运行此脚本才能在您的 lib/ 文件夹中找到 cloudstorage 库

4。同一教程中的“将文件写入云存储”:

    def create_file(self, filename):
    """Create a file."""

       self.response.write('Creating file {}\n'.format(filename))

       # The retry_params specified in the open call will override the default
       # retry params for this particular file handle.
       write_retry_params = cloudstorage.RetryParams(backoff_factor=1.1)
       with cloudstorage.open(
           filename, 'w', content_type='text/plain', options={
               'x-goog-meta-foo': 'foo', 'x-goog-meta-bar': 'bar'},
               retry_params=write_retry_params) as cloudstorage_file:
                   cloudstorage_file.write('abcde\n')
                   cloudstorage_file.write('f'*1024*4 + '\n')
       self.tmp_filenames_to_clean_up.append(filename) 

       with cloudstorage.open(
           filename, 'w', content_type='text/plain', options={
               'x-goog-meta-foo': 'foo', 'x-goog-meta-bar': 'bar'},
               retry_params=write_retry_params) as cloudstorage_file:
                   cloudstorage_file.write('abcde\n')
                   cloudstorage_file.write('f'*1024*4 + '\n')

其中文件名是 /bucket_name/file_suffix

4。通过 WSGI 应用程序中的路由调用 create_file 后,您的文件将在以下位置可用:

    localhost:port/_ah/gcs/bucket_name/file_suffix

默认端口为8080,文件写入:/bucket_name/file_suffix

后记

很遗憾,我在他们的文档中没有找到 3) 或 4),所以我希望这有助于将来有人更轻松地进行设置。

【讨论】:

  • 比尔你是个英雄。你遇到的每一个问题我都独立遇到过。
  • 谢谢比尔,我发现要在使用遥控器时读取文件,我必须设置 HTTP_HOST 环境变量:os.environ['HTTP_HOST'] = 'localhost:8080'
【解决方案2】:

本地服务器的存储模拟器在更高版本的 SDK 中工作。对于 Java,可以选择遵循专门的教程:“App Engine and Google Cloud Storage Sample”。

【讨论】:

    【解决方案3】:

    要访问 dev_appserver 上的 gcs 对象,您必须指定存储桶和对象名称,即 /_ah/gcs/[bucket]/[object]。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-03
      • 1970-01-01
      • 1970-01-01
      • 2012-09-02
      • 2020-09-10
      相关资源
      最近更新 更多