much like this question, I'm trying to follow the simple Flask tutorial for file upload to a flask server. In my specific case, I'm trying to upload an XML file.
The (simplified) HTML I'm using is:
<form action="" method="post" enctype="multipart/form-data">
<input type="file">
<input type="submit" value="Let's go!">
</form>
The request is correctly handled by a if request.method == 'POST':
block, so I put in some print statements to troubleshoot:
print('request.method', request.method)
print('request.args', request.args)
print('request.form', request.form)
print('request.files', request.files)
and the result was the following:
request.method POST
request.args ImmutableMultiDict([])
request.form ImmutableMultiDict([])
request.files ImmutableMultiDict([])
What am I doing wrong? I can provide more complete source code if needed.
As always, I found the answer mere minutes after posting this question. I'm answering here to hopefully help someone else.
The problem was that my file input had no name
attribute. Thanks to Ben here I was able to fix this problem by adding a name
attribute to the file input, and now the file upload is being processed correctly.
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