How do I access an uploaded file with Bottle?

非 Y 不嫁゛ 提交于 2019-12-12 04:33:47

问题


I'd like to upload a text file with bottle, and then read it. How can I do this? Below is what I've tried and didn't work.

HTML:

<form action="/load_from_file" method="post">
  <div>
    Load File: <input type="file" name="file"/>
    <input type="submit" value="Submit"/>
  </div>
</form>

Bottle route:

@post('/load_from_file')
def load_from_file():
    list_file = request.forms.get("file")
    print request.files.get("file")
    print request.files["file"]
    return "how do I get the uploaded file?"

回答1:


You should add attribute enctype="multipart/form-data" to form tag.



来源:https://stackoverflow.com/questions/12361581/how-do-i-access-an-uploaded-file-with-bottle

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!