【问题标题】:Asynchronous requests from App Engine to Cloud Storage从 App Engine 到 Cloud Storage 的异步请求
【发布时间】:2015-07-16 11:52:05
【问题描述】:

在我的 App Engine 应用中,我使用 Python Client for Google App Engine 从 Cloud Storage 读取数据。

当我从 Cloud Storage 读取多个文件时,是否可以选择使此过程异步?

【问题讨论】:

  • 你必须使用带有异步 urlfetch 的 json API。

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


【解决方案1】:

要扩展 voscause 所说的内容,您可以执行以下操作。请记住,这仅适用于实时服务器,因为不会在开发人员上创建访问令牌。如果您想在开发人员上进行测试,请注释掉标头并将文件公开。

urls = [] #List of url's with http://

scope = 'https://www.googleapis.com/auth/devstorage.full_control'
token, _ = app_identity.get_access_token(scope)

rpcs = []
for url in urls:
    rpc = urlfetch.create_rpc()

    urlfetch.make_fetch_call(rpc, url,method=urlfetch.GET,
                             headers={'Authorization': 'OAuth %s' % token})
    rpcs.append(rpc)

# Finish all RPCs
for rpc in rpcs:
    self.response.write(rpc.get_result().content)
    self.response.write("</p>")

【讨论】:

猜你喜欢
  • 2013-11-02
  • 1970-01-01
  • 1970-01-01
  • 2021-12-06
  • 2016-01-11
  • 2015-07-07
  • 2013-01-26
  • 1970-01-01
  • 2014-01-16
相关资源
最近更新 更多