python - GAE/P : Serve file directly from GCS to user without reading into GAE memory

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

在我的 App Engine 应用程序中,我使用 GCS Python Client library存储一些文件。

目前,为了向用户提供文件,我执行以下操作:

  1. 使用 GCS Python 客户端库将文件从 GCS 读取到 App Engine
  2. 使用 webapp2 将文件提供给用户 (self.response.write(...))

似乎应该有一种方法可以直接向用户提供此文件。

我不想修改 ACL,因为文件需要保持私有(private),但如果不必将文件读入 GAE 内存即可将其提供给用户,那就太好了。

有更好的解决方案吗?

最佳答案

生成签名 URL,然后将签名 URL 发送到客户端。然后,客户端可以使用签名的 URL 直接从 GCS 下载数据。您可以在 URL 上设置过期时间,以便它仅在您的应用程序可接受的时间内有效。

文档中的更多信息 -> https://cloud.google.com/storage/docs/access-control#Signed-URLs

这是一些示例 python 代码 -> https://github.com/GoogleCloudPlatform/storage-signedurls-python

关于python - GAE/P : Serve file directly from GCS to user without reading into GAE memory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29211286/

相关文章:

python - Redisearch 前缀搜索始终返回多个字段索引的总计最大值 200

python - 如何在使用 izip_longest 向前查看的同时一次访问 2 个列表? -Python

Python pip 从 pip freeze 的输出中找出基本要求

python - Google App Engine Datastore 多行条目未在 HTML 中显示为多行

firebase - 云函数内如何获取存储file.txt内容

Python - 如何在 "if x in range"语句中使用 float

python - 如何对类实例列表进行排序

google-app-engine - 如何在GAE中管理上传的代码?

google-cloud-platform - 使用 terraform 创建多个 GCP 存储桶

google-cloud-storage - 如何计算桶中对象的数量?