使用Mailgun和Bottle发送用户上传的附件

时间:2016-05-18 07:29:31

标签: python bottle mailgun

我正在关注MailGun的文档以附加文件,但所有示例都已经选择了一个文件。如何发送用户上传的附件?

代码在发送消息时工作正常,但是当我添加此部分时......

files=[("attachment", open(request.files.data.file)),],

我收到此错误:

TypeError: invalid file: <_io.BufferedRandom name=19>

HTML表单

<form action="/subr" method="post" enctype="multipart/form-data">
<input id="main" name="em" type="email"  placeholder="E-MAIL" required><br>
<textarea id="main" name="about"  placeholder="DESCRIBE THE FILE"></textarea><br>
<input id="main" type="file" name="data" required>
 <button type="submit">SUBMIT FILE</button>
</form>

瓶子路线:

@route('/subr', method='POST')
def submitr():
    subject = "File Submission"
    item1 =  request.forms.get('em')
    item2 =  request.forms.get('about')
    text = str(item1) + " " + str(item2)
    requests.post("https://api.mailgun.net...",
    auth=("api", "key-4..."),
    files=[("attachment", open(request.files.data.file)),],
    data={"from": "Mailgun Sandbox <postmaster@sandboxe....mailgun.org>",
        "to": "Me <me@gmail.com>",
        "subject": subject,
        "html": text})
    return "<p>Success</p>"

感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

p=[px;py]; pd=p; p(:,end)=[]; pd(:,1)=[]; p=[[0;0] p]; pd=[[0; 0] pd]; displacement=sqrt((pd(1,:)-p(1,:)).^2+(pd(2,:)-p(2,:)).^2); cdisp=cumsum(displacement); plot(t,cdisp); 已经打开;只是从中读取。这有用吗?

request.files.data.file