gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 23:13:38 25 4
gpt4 key购买 nike

在我的 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/

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