Sometimes, we want to upload multiple files with Python Flask.
In this article, we’ll look at how to upload multiple files with Python Flask.
How to upload multiple files with Python Flask?
To upload multiple files with Python Flask, we can use the request.files.getlist
method.
For instance, we write
@app.route("/upload", methods=["POST"])
def upload():
uploaded_files = flask.request.files.getlist("file[]")
print(uploaded_files)
return ""
to create the upload
view that gets the files from flask.request.files.getlist
with the key of the form data that has the files.
Then we can do whatever we want with the files in the uploaded_files
list.
Conclusion
To upload multiple files with Python Flask, we can use the request.files.getlist
method.