Let's say the app received a message, which has attachments (mail_message.attachments
). Now, I would like to save the message in the datastore. I don't want to store attachment there, so I would like to keep there blobstore keys only. I know that I can write files to blobstore. The questions I have:
- how to extract files from the mail attachment;
- how to keep original filenames;
- how to store blob keys in the datastore (taking into account that one mail can contain several attachments looks like
BlobKeyProperty()
doesn't work in this case).
Upd. For (1) the following code can be used:
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)))