我们假设应用程序收到一条消息,其中has attachments(mail_message.attachments
)。现在,我想将该消息保存在数据存储中。我不想在那里存储附件,所以我只想保留blobstore密钥。我知道我可以write files to blobstore。我有的问题:如何将电子邮件附件存储到GAE Blobstore?
- 如何从邮件附件中提取文件;
- 如何保留原文件名;
- 如何在数据存储中存储blob密钥(考虑到一个邮件可能包含几个附件,看起来像
BlobKeyProperty()
在这种情况下不起作用)。
Upd。对于(1)the following code可用于:
my_file = []
my_list = []
if hasattr(mail_message, 'attachments'):
file_name = ""
file_blob = ""
for filename, filecontents in mail_message.attachments:
file_name = filename
file_blob = filecontents.decode()
my_file.append(file_name)
my_list.append(str(store_file(self, file_name, file_blob)))
谢谢,我使用NDB(请参阅标签)。 –