Appengine Dev Server上的Google云端存储

时间:2013-11-23 03:26:46

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

最近在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错误。

只是抬头,安装库我所做的就是将代码拖放到我的app文件夹中。我想知道我是否可以跳过设置步骤?我无法在文档中找到答案!

谢谢!

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

3 个答案:

答案 0 :(得分:3)

我能够找到我在本地写入存储桶的Google云端存储文件:

    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 Sample”:

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

如果您遇到“ImportError:没有名为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')

其中filename是/ bucket_name / file_suffix

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

    localhost:port/_ah/gcs/bucket_name/file_suffix

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

后记

不幸的是,我在他们的文档中没有找到3)或4),所以我希望这有助于将来更容易设置。

答案 1 :(得分:2)

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

答案 2 :(得分:0)

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