Uploading multiple files with Flask
You can use method getlist of flask.request.files, for example:
@app.route("/upload", methods=["POST"])def upload(): uploaded_files = flask.request.files.getlist("file[]") print uploaded_files return ""
@app.route('/upload', methods=['GET','POST'])def upload(): if flask.request.method == "POST": files = flask.request.files.getlist("file") for file in files: file.save(os.path.join(app.config['UPLOAD_FOLDER'], file.filename))
It works for me.
for UPLOAD_FOLDER if you need add this just after app = flask.Flask(name)
UPLOAD_FOLDER = 'static/upload'app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
Using Flask 1.0.2+:
files = request.files.getlist("images")
Where images
is the key of the key/value pair. With the Value being the multiple images.