从AppEngine中的blob接收静态URL

oli*_*r13 1 python google-app-engine blobstore

在我的应用程序中,我正在创建一个在App Engine仪表板中正确上传的blob.但是,此创建的文件需要通过电子邮件发送给相应的人.为了做到这一点,我要么将文件本身作为附件,要么是这个人可以下载的静态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()
Run Code Online (Sandbox Code Playgroud)

Seb*_*eft 5

如果要提供文件,请查看Blobstore概述 - 提供Blob.

如果要将其作为附件发送,请参阅附件文档.您需要获取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()
Run Code Online (Sandbox Code Playgroud)