gpt4 book ai didi

google-app-engine - Appengine 开发服务器上的谷歌云存储

转载 作者:太空宇宙 更新时间:2023-11-03 15:20:14 25 4
gpt4 key购买 nike

最近在 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 来托管它。

最佳答案

我能够找到我写入本地存储桶的谷歌云存储文件:

    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),所以我希望这有助于将来的人更轻松地进行设置。

关于google-app-engine - Appengine 开发服务器上的谷歌云存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20158135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com