Is there a way to receive multiple uploaded files with Flask? I've tried the following:
<form method="POST" enctype="multipart/form-data" action="/upload">
<input type="file" name="file[]" multiple="">
<input type="submit" value="add">
</form>
And then printed the contents of request.files['file']
:
@app.route('/upload', methods=['POST'])
def upload():
if not _upload_dir:
raise ValueError('Uploads are disabled.')
uploaded_file = flask.request.files['file']
print uploaded_file
media.add_for_upload(uploaded_file, _upload_dir)
return flask.redirect(flask.url_for('_main'))
If I upload multiple files, it only prints the first file in the set:
<FileStorage: u'test_file.mp3' ('audio/mp3')>
Is there a way to receive multiple files using Flask's built-in upload handling? Thanks for any help!
Using Flask 1.0.2:
Where
images
is the key of the key/value pair. With the Value being the multiple images.You can use method getlist of flask.request.files, for example:
For those who are still searching for the solution to this problem please refer to this answer because the above answers did not work for me this is a working solution for flask version '1.0.2':
basically, images[image] has an image file with save function added to it Now do whatever you like to do with the data.