Categories
Python Answers

How to upload multiple files with Python Flask?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *