I have the following
<form action="classify_upload" method="post" id="upload-form">
<input type="file" name="imagefile" id="imagefile"/>
<input type="submit" />
</form>
And in my flask webapp I have the following rule:
@webapp.route('/upload', methods=['POST'])
def upload():
try:
imagefile = flask.request.files['imagefile']
...
except Exception as err:
...
But I am getting a error 400: bad request
, which from my googling tells me Flask can not find the file under the key 'imagefile'
which is the name of the input in the html. Any ideas why it is not finding it?
Turns out I need to include the enctype
in the form, so the html should be
<form action="classify_upload" method="post" id="upload-form" enctype="multipart/form-data">
<input type="file" name="imagefile" id="imagefile"/>
<input type="submit" />
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With