我能够在以下位置找到我写入本地存储桶的谷歌云存储文件:
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),所以我希望这有助于将来有人更轻松地进行设置。