I am trying to follow this simple tutorial for filing files in a flask. I use the following HTML form to submit files:
<form action="" method="post" "enctype=multipart/form-data"> <table border="0" summary=""><tbody> <tr> <th> <label for="image_file">Your image:</label> </th> <td> <input type="file" id="image_file" name="image_file"></input> </td> </tr> <tr> <td> </td> <td> <input type="submit" value="Submit" /> <a href="/test_func">Cancel</a> </td> </tr> </tbody></table> </form>
After submitting the form, I check the contents of the request variable as follows:
print 'request.method', request.method print 'request.args', request.args print 'request.form', request.form print 'request.files', request.files
As a result, I get the following:
request.method POST request.args ImmutableMultiDict([]) request.form ImmutableMultiDict([('image_file', u'badge.gif')]) request.files ImmutableMultiDict([])
What I don't understand is that request.files empty. According to the tutorial above, I need to use file = request.files['file'] to get the file object (to save it).
What am I doing wrong?
source share