user886596
user886596

Reputation: 2440

How do I access an uploaded file with Bottle?

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?"

Upvotes: 0

Views: 1337

Answers (1)

iMom0
iMom0

Reputation: 12931

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

Upvotes: 4

Related Questions