GAE(Python)将文件上传+电子邮件文件作为附件 [英] GAE (Python) form file upload + email file as attachment

查看:186
本文介绍了GAE(Python)将文件上传+电子邮件文件作为附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Google App Engine(GAE-Python)上实现一个相当简单的Web表单,该表单接受一些表单输入(名称,电子邮件,电话)和简历(通常为TXT,PDF或DOC / DOCX)文件。一旦提交表格,我希望通过电子邮件发送表格内容,并在表格中提交文件时,将其作为附件包含在同一封电子邮件中指定的电子邮件地址。

I need to implement a rather simple web form on Google App Engine (GAE-Python) that accepts some form input (name, email, telephone) and a resume (typically TXT, PDF or DOC/DOCX) file. Once the form is submitted, I want to contents of the form to be emailed and if a file is submitted in the form, for it to be included as an attachment in the same email to a designated email address.


  1. 通过电子邮件发送/附加后,我不需要该文件存在。有点像临时文件,或者存储在临时blob存储中。
  2. 使用HTML5和jQuery,有很多花哨的用户界面来实现文件上传。是否有任何推荐的方法可以使用这些与GAE很好地配合使用的方法,以及如果浏览器不支持现代方法(即IE),就能够优雅地退化?

我使用jinja2框架,如果这是相关的。 (我是一个Python新手顺便说一句)

I am using jinja2 framework, if that is relevant. (I am a Python novice by the way)

预先感谢!

Thanks in advance!

推荐答案

要在GAE中将文件上传为blob,您需要 webapp 内置框架中的 blobstore_handlers
文档的完整示例用于上传文件和我不认为有其他方式上传到blobstore。

For upload a file as a blob in GAE you need the blobstore_handlers from built-in framework called webapp. The docs have a complete sample for upload files and I do not think there are other ways to upload to the blobstore.

当你有blob的时候,请从 docs 将该blob附加到电子邮件中。

When you have the blob see the first sample of this page from docs for attach the blob to the email.

现在,对于临时文件解决方案,您可以尝试一种不同的方式:使用StringIO python模块将上传文件写入内存。类似的东西:

Now, for a "temp file solution" you can try a different way: write the upload file to the ram with StringIO python module. Something like that:

<form action="/test/" method="POST" enctype="multipart/form-data">
  <input type="file" name="file"><br>
  <input type="submit"name="submit" value="Submit">
</form>



def post(self):
    output = StringIO.StringIO()
    upload = self.request.get('file')
    output.write(upload)
    self.response.write(output.getvalue())

这篇关于GAE(Python)将文件上传+电子邮件文件作为附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆