Previously, I did not know how to upload multiple files with Flask, so I made a trial and error, so a memo of the result
Server-side processing
if request.files.getlist('upload_files')[0].filename:
upload_files = request.files.getlist('upload_files')
for upload_file in upload_files:
#Tmp the received file/Save to
upload_file.save("tmp/" + secure_filename(upload_file.filename))
Client-side HTML
<form method="post">
<div class="form-group pull-left">
<input type="file" id="upload_files" name="upload_files" multiple="multiple" class="form-control">
<p class="help-block">* Multiple files can be specified</p>
</div>
<div class="form-group">
<input type="submit" value="Send" class="form-control btn btn-primary">
</div>
</from>
It was easy to specify multiple items on the client side and send them, but I was struggling because I was not sure how to receive them on the server side. .. .. As a result of various investigations, when multiple files are sent, it seems that they are stored in request.files with the same KEY, so it is solved by getting from request.files with "getlist ()" instead of "get ()".
Recommended Posts