To upload a list of files with the same key value in a single request, you can create a list of tuples with the first item in each tuple as the key value and the file object as the second:

files = [('file', open('report.xls', 'rb')), ('file', open('report2.xls', 'rb'))]
Answer from lazyboy on Stack Overflow
🌐
Stack Abuse
stackabuse.com › how-to-upload-files-with-pythons-requests-library
How to Upload Files with Python's requests Library
September 19, 2021 - In this article, we learned how to upload files in Python using the requests library. Where it's a single file or multiple files, only a few tweaks are needed with the post() method.
Discussions

how to upload multiple files using flask in python - Stack Overflow
Here is my code for multiple files upload: HTML CODE: Browse PYTHON CODE: pro_attachment = request.files.getlist(' More on stackoverflow.com
🌐 stackoverflow.com
September 3, 2017
How to upload multiple files within single call (using files.upload)?
I'm using slackclient v1 (because ... with Python 2). According to the files.upload documentation, when we uploading file using file field it will load file content as a multipart/form-data. However, I could not figure-out how to provide input for this parameter (through the api_call) when I want to upload multiple files at ... More on github.com
🌐 github.com
11
June 12, 2019
POST with multiple files with the form-data sends only 1 file.
POSTing multiple files with a form-data. Using this doc: https://requests.readthedocs.io/en/latest/user/advanced/#post-multiple-multipart-encoded-files However only 1 file is received by the endpoint. But if you change the files array (d... More on github.com
🌐 github.com
4
February 24, 2024
Upload multiple *.docx files from folder into the sharepoint
Hello All…I have multiple *.docx files in server folder…I want to upload those files into sharepoint using python. Please help me on how to get it done…thanks a lot. More on discuss.python.org
🌐 discuss.python.org
3
0
April 14, 2023
🌐
GeeksforGeeks
geeksforgeeks.org › python › upload-multiple-files-with-flask
Upload Multiple files with Flask - GeeksforGeeks
July 23, 2025 - Step 1: Create a new project folder Upload. Inside this folder create main.py, and create folder templates. Step 2: Create a simple HTML page index.html to select multiple files and submit them to upload files on the server.
🌐
Roy Tutorials
roytuts.com › home › python › flask › python flask multiple files upload example
Python Flask Multiple Files Upload Example - Roy Tutorials
January 11, 2024 - If you want to upload multiple files then you need to hold CTRL key and select files. <!doctype html> <title>Python Flask Multiple Files Upload Example</title> <h2>Select file(s) to upload</h2> <p> {% with messages = get_flashed_messages() %} ...
Top answer
1 of 2
16

How to

In the template, you need to add mulitple attribute in upload input:

<form method="POST" enctype="multipart/form-data">
    <input type="file" name="photos" multiple>
    <input type="submit" value="Submit">
</form>    

Then in view function, the uploaded files can get as a list through request.files.getlist('photos'). Loop this list and call save() method on each item (werkzeug.datastructures.FileStorage) will save them at given path:

import os

from flask import Flask, request, render_template, redirect

app = Flask(__name__)
app.config['UPLOAD_PATH'] = '/the/path/to/save'

@app.route('/upload', methods=['GET', 'POST'])
def upload():
    if request.method == 'POST' and 'photo' in request.files:
        for f in request.files.getlist('photo'):
            f.save(os.path.join(app.config['UPLOAD_PATH'], f.filename))
        return 'Upload completed.'
    return render_template('upload.html')

Furthermore, you may need to use secure_filename() to clean filename:

# ...
from werkzeug.utils import secure_filename
# ...
    for f in request.files.getlist('photo'):
        filename = secure_filename(f.filename)
        f.save(os.path.join(app.config['UPLOAD_PATH'], filename))
        # ...

You can also generate a random filename with this method.

Full demo

View:

import os

from flask import Flask, request, render_template
from werkzeug.utils import secure_filename

app = Flask(__name__)  
app.config['UPLOAD_PATH'] = '/the/path/to/save'

@main.route('/upload', methods=['GET', 'POST'])
def upload():
    form = UploadForm()
    if form.validate_on_submit() and 'photo' in request.files:
        for f in request.files.getlist('photo'):
            filename = secure_filename(f.filename)
            f.save(os.path.join(app.config['UPLOAD_PATH'], filename))
        return 'Upload completed.'
    return render_template('upload.html', form=form)

Form:

from flask_wtf import FlaskForm
from wtforms import SubmitField
from flask_wtf.file import FileField, FileAllowed, FileRequired

class UploadForm(FlaskForm):
    photo = FileField('Image', validators=[
        FileRequired(),
        FileAllowed(photos, 'Image only!')
    ])
    submit = SubmitField('Submit')

Template:

<form method="POST" enctype="multipart/form-data">
    {{ form.hidden_tag() }}
    {{ form.photo(multiple="multiple") }}
    {{ form.submit }}
</form>

More

For better upload experience, you can try Flask-Dropzone.

2 of 2
3

Your code looks perfect. I think the only mistake your making is splitting and taking the first value. And also i dont know about the rsplit(), but the split() works perfect for me.

HTML CODE


<input id="upload_img" name="zip_folder"  type="file" multiple  webkitdirectory  >

PYTHON CODE

@app.route('/zipped',methods = ['GET', 'POST'])
def zipped():
    if request.method == 'POST':
        f = request.files.getlist("zip_folder")
        print f
        for zipfile in f:
            filename = zipfile.filename.split('/')[1]
            print zipfile.filename.split('/')[1]
            zipfile.save(os.path.join(app.config['ZIPPED_FILE'], filename))
        return render_template('final.html')
🌐
GitHub
github.com › slackapi › python-slack-sdk › issues › 442
How to upload multiple files within single call (using files.upload)? · Issue #442 · slackapi/python-slack-sdk
June 12, 2019 - Description I'm using slackclient v1 (because I need compatibility with Python 2). According to the files.upload documentation, when we uploading file using file field it will load file content as a multipart/form-data. However, I could ...
Author   stojan-jovic
Find elsewhere
🌐
Sensible
sensible.so › blog › python-upload-files
Six Methods to Upload Files in Python | Sensible Blog
You can use the requests library to upload multiple files to any API endpoint in the same request. Save the following code in a file named requests-test.py in a new directory named multiple and run the command python3 requests-test.py in a new ...
🌐
GitHub
github.com › psf › requests › issues › 6648
POST with multiple files with the form-data sends only 1 file. · Issue #6648 · psf/requests
February 24, 2024 - import requests url = "https://endpoint.com/api/upload" payload = {} files=[ ('images',('image01.png',open('H:/image01.png','rb'),'image/png')), ('images',('image02.png',open('H:/image02.png','rb'),'image/png')) ] headers = {} response = requests.post(url, files=files) print(response.text) Endpoint will get only 1 file. If you change files array to make images have separate value for each file = endpoint gets 2 files. $ python -m requests.help ·
Author   geekbeard
🌐
WebScraping.AI
webscraping.ai › faq › requests › how-do-i-send-multiple-files-in-a-single-request-using-requests
How do I send multiple files in a single request using Requests? | WebScraping.AI
# Method 3: Just file objects (uses original filename) with open('config.json', 'rb') as config, open('data.csv', 'rb') as data: files = { 'config': config, 'dataset': data } response = requests.post(url, files=files) # Uploading multiple images with same form field name image_files = ['photo1.jpg', 'photo2.jpg', 'photo3.jpg'] files = [] for i, filepath in enumerate(image_files): files.append(('images', (f'image_{i+1}.jpg', open(filepath, 'rb'), 'image/jpeg'))) response = requests.post(url, files=files) # Don't forget to close the files for _, (_, file_obj, _) in files: file_obj.close()
🌐
FastAPI
fastapi.tiangolo.com › tutorial › request-files
Request Files - FastAPI
The files will be uploaded as "form data". If you declare the type of your path operation function parameter as bytes, FastAPI will read the file for you and you will receive the contents as bytes.
🌐
Beautiful Soup
tedboy.github.io › requests › adv10.html
3.10. POST Multiple Multipart-Encoded Files — Requests API
>>> url = 'http://httpbin.org/post' >>> multiple_files = [ ('images', ('foo.png', open('foo.png', 'rb'), 'image/png')), ('images', ('bar.png', open('bar.png', 'rb'), 'image/png'))] >>> r = requests.post(url, files=multiple_files) >>> r.text { ... 'files': {'images': 'data:image/png;base64,iVBORw ....'} 'Content-Type': 'multipart/form-data; boundary=3131623adb2043caaeb5538cc7aa0b3a', ...
🌐
Medium
medium.com › @dustindavignon › upload-multiple-images-with-python-flask-and-flask-dropzone-d5b821829b1d
Upload multiple images with Python, Flask and Flask-Dropzone | by Dustin D'Avignon | Medium
November 23, 2017 - Now that we let Flask know that the index route can except post requests, we can grab the data from the uploaded files from the request object. Since we are allowing Dropzone to upload multiple files, we need to iterate through the file object to get our individual uploads.
🌐
DEV Community
dev.to › ndrbrt › python-upload-multiple-files-concurrently-with-aiohttp-and-show-progress-bars-with-tqdm-32l7
Python: upload multiple files concurrently with aiohttp and show progress bars with tqdm - DEV Community
January 25, 2025 - import os import asyncio import aiohttp import aiofiles from tqdm import tqdm class FileManager(): def __init__(self, file_name: str): self.name = file_name self.size = os.path.getsize(self.name) self.pbar = None def __init_pbar(self): self.pbar = tqdm( total=self.size, desc=self.name, unit='B', unit_scale=True, unit_divisor=1024, leave=True) async def file_reader(self): self.__init_pbar() chunk_size = 64*1024 async with aiofiles.open(self.name, 'rb') as f: chunk = await f.read(chunk_size) while chunk: self.pbar.update(chunk_size) yield chunk chunk = await f.read(chunk_size) self.pbar.close()
🌐
PythonAnywhere
pythonanywhere.com › forums › topic › 778
How to add multiple files or directories ? : Forums : PythonAnywhere
totally stupid that pythonanywhere doesn't allow this. now i know why i rarely use it. just stupid. deleted-user-5320414 | 1 post | July 17, 2019, 2:50 p.m. | permalink ... How you create one on your own machine depends on what operating system you use; once you have one, you can upload it on the "Files" page, and then use the unzip command from bash to extract from zip files, or the unrar one to extract from rar files.
🌐
Medium
medium.com › @purusharma021 › how-to-upload-multiple-files-in-fastapi-bf159cbc2835
How to Upload Multiple Files in FastAPI | by Purusharma | Medium
June 9, 2024 - Pydantic Models: Defined in serializers.py for validating incoming request data. UserDetails handles user data, and UpdateInvoiceDocuments handles multiple invoice document paths. FastAPI Application: In app.py, we set up the application and define routes: ... upload_files: Endpoint for uploading multiple files to S3.