0

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?"
user886596
  • 2,380
  • 5
  • 31
  • 53

1 Answers1

4

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

iMom0
  • 12,493
  • 3
  • 49
  • 61
  • 1
    This works, thanks. I'll add that "request.files.get("file")" seems to be the right syntax to get the file. – user886596 Sep 11 '12 at 02:45