gpt4 book ai didi

python - 在 AppEngine 中接收来自 blob 的静态 URL

转载 作者:太空宇宙 更新时间:2023-11-04 09:13:17 25 4
gpt4 key购买 nike

在我的应用程序中,我正在创建一个 blob,该 blob 已正确上传到 App Engine 仪表板。但是,这个创建的文件需要通过电子邮件发送给相应的人。为此,我要么需要文件本身作为附件,要么需要一个此人可以下载它的静态 URL。我无法弄清楚如何从 blobkey 获取静态 URL。

这是创建文件的代码,不过没什么特别的:

    file_name = files.blobstore.create(mime_type='text/csv')
with files.open(file_name, 'a') as f:
f.write(dataset)
files.finalize(file_name)
blob_key = files.blobstore.get_blob_key(file_name)
blob_info = blobstore.BlobInfo.get(blob_key)

new_url = blob_key.urlsafe()

最佳答案

如果要提供文件,请查看 Blobstore Overview - Serving a Blob .

如果您想将其作为附件发送,请参阅 Attachments Documentation .您将需要 fetch the contents of the blob然后将其附加到邮件中。

from google.appengine.ext import blobstore

# blob_key = ...

# Instantiate a BlobReader for a given Blobstore value.
blob_reader = blobstore.BlobReader(blob_key)

# Read the entire value into memory. This may take a while depending
# on the size of the value and the size of the read buffer, and is not
# recommended for large values.
blob_contents = blob_reader.read()

关于python - 在 AppEngine 中接收来自 blob 的静态 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12464520/

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