FileStorage contains stream field. This object must extend IO or file object, so it must contain read and other similar methods. FileStorage also extend stream field object attributes, so you can just use file.read() instead file.stream.read(). Also you can use save argument with dst parameter as StringIO or other IO or file object to copy FileStorage.stream to another IO or file object.

See documentation: http://flask.pocoo.org/docs/api/#flask.Request.files and http://werkzeug.pocoo.org/docs/datastructures/#werkzeug.datastructures.FileStorage.

Answer from tbicr on Stack Overflow
🌐
Beautiful Soup
tedboy.github.io › flask › generated › generated › flask.Request.files.html
flask.Request.files — Flask API
flask.Request.files · View page source · Request.files¶ · MultiDict object containing all uploaded files. Each key in files is the name from the <input type="file" name="">. Each value in files is a Werkzeug FileStorage object. Note that files will only contain data if the request method ...
🌐
Miguel Grinberg
blog.miguelgrinberg.com › post › handling-file-uploads-with-flask
Handling File Uploads With Flask - miguelgrinberg.com
July 8, 2020 - The request.form and request.files dictionaries are really "multi-dicts", a specialized dictionary implementation that supports duplicate keys. This is necessary because forms can include multiple fields with the same name, as is often the case with groups of check boxes. This also happens with file fields that allow multiple files. Ignoring important aspects such as validation and security for the moment, the short Flask application shown below accepts a file uploaded with the form shown in the previous section, and writes the submitted file to the current directory:
Discussions

python - How to do POST using requests module with Flask server? - Stack Overflow
I am having trouble uploading a file to my Flask server using the Requests module for Python. import os from flask import Flask, request, redirect, url_for from werkzeug import secure_filename More on stackoverflow.com
🌐 stackoverflow.com
[Ask Flask] How to receive and save a file?
Copy/paste almost straight from a project, no guarantee it will work:/ app.route('/upload', methods=\['GET', 'POST'\]) def upload(): if request.method == 'POST': if 'file' not in request.files: flash('No file') return redirect(request.url) file = request.files\['file'\] if not file: flash('No file') return render_template('form/file.html', filetype=filetype) if allowed_file(file.filename): if file.mimetype[:5] == 'image': save_img(file, g.user.kt, request.form['description']) flash('Image saved') else: save_doc(file,int(request.form['filetype']),request.form['description']) flash('File saved') return redirect(url\_for('documents')) else: flash('This file is not allowed.') return render_template('form/file.html', filetype=filetype, files=files) And save_file is basically def save_file(file): file.save(fullpathandname) Hope this helps More on reddit.com
🌐 r/flask
6
4
February 5, 2020
python - Flask request.files is empty - Stack Overflow
much like this question, I'm trying to follow the simple Flask tutorial for file upload to a flask server. In my specific case, I'm trying to upload an XML file. The (simplified) HTML I'm using is... More on stackoverflow.com
🌐 stackoverflow.com
python - Flask request.files is not in 'file' - Stack Overflow
I am using Flask Python to integrate a website with a python script. In such a page user should enter an image the this image is passed to the python script to do some processing on it. The problem... More on stackoverflow.com
🌐 stackoverflow.com
July 26, 2020
🌐
Flask
flask.palletsprojects.com › en › stable › patterns › fileuploads
Uploading Files — Flask Documentation (3.1.x)
The application accesses the file from the files dictionary on the request object. use the save() method of the file to save the file permanently somewhere on the filesystem. Let’s start with a very basic application that uploads a file to a specific upload folder and displays a file to the user.
🌐
ProgramCreek
programcreek.com › python › example › 51528 › flask.request.files
Python Examples of flask.request.files
def whitelist_add(): log.info("whitelist_add called") try: file_ = request.files["file"] handle, filename = tempfile.mkstemp() os.close(handle) file_.save(filename) data = request.get_json() if data and "functions" in data: functions = data["functions"] else: functions = None bass.whitelist_add(filename, functions) os.unlink(filename) except KeyError: log.exception("") return make_response(jsonify(message = "Sample file 'file' missing in POST request"), 400) return jsonify(message = "OK")
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-upload-file-in-python-flask
How to Upload File in Python-Flask - GeeksforGeeks
July 23, 2025 - from distutils.log import debug from fileinput import filename from flask import * app = Flask(__name__) @app.route('/') def main(): return render_template("index.html") @app.route('/success', methods = ['POST']) def success(): if request.method == 'POST': f = request.files['file'] f.save(f.filename) return render_template("Acknowledgement.html", name = f.filename) if __name__ == '__main__': app.run(debug=True)
🌐
Stack Abuse
stackabuse.com › step-by-step-guide-to-file-upload-with-flask
Step-by-Step Guide to File Upload with Flask
May 23, 2025 - Files that are uploaded in a Flask application are stored in the request.files dictionary. The keys of this dictionary are the names of the file input fields from your HTML form, while the values are FileStorage instances.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › flask › flask_file_uploading.htm
Flask File Uploading
Forms post method invokes /upload_file URL. The underlying function uploader() does the save operation. Following is the Python code of Flask application. from flask import Flask, render_template, request from werkzeug import secure_filename app = Flask(__name__) @app.route('/upload') def upload_file(): return render_template('upload.html') @app.route('/uploader', methods = ['GET', 'POST']) def upload_file(): if request.method == 'POST': f = request.files['file'] f.save(secure_filename(f.filename)) return 'file uploaded successfully' if __name__ == '__main__': app.run(debug = True) Print Page ·
🌐
Reddit
reddit.com › r/flask › [ask flask] how to receive and save a file?
r/flask on Reddit: [Ask Flask] How to receive and save a file?
February 5, 2020 -

Hi I'm using react native frontend and flask backend. I am trying to send an audio file from the phone to the server so the server can save it. For image uploads I encode the image as base64 string, send it and on Flask I decode it and save the image and everything works fine. But for the audio the react native gives me basically just the URI on the phone, and all the tutorials are saying that I should send it with FormData in format like

var formData =new FormData();
formData.append('file', JSON.stringify({
                name: filename,
                filename: filename+'.mp4',
                filepath: fsPath,
                filetype: 'audio/x-mp4'
               })
}

But I am confused how I am supposed to actually download or get the file once I receive it in the Flask. All I have is a JSON object with filename, type, and the internal phone filepath. I have no idea how to actually convert that into some data that I can save as a file.

The Flask tutorial has an article about how to upload files with HTML <form inputType=file> but they receive it as request.files[] whereas I receive it as request.form['file'], whereas since I'm doing everything in JS code everyone is saying that I should use FormData which is kind of making me confused whether I am not sending it correctly (I posted a question on reactnative sub as well) but also maybe I don't know how to receive it.

Thank you for any help!

🌐
Python Basics
pythonbasics.org › flask-upload-file
Upload a File with Python Flask - Python Tutorial
Related course: Python Flask: Create Web Apps with Flask · Each uploaded file is first saved on a temporary location on the server, and then will actually be saved to its final location. The name of the target file can be hard-coded or available from the filename property of file] request.files object.
🌐
Faculty
docs.faculty.ai › user-guide › apis › flask_apis › flask_file_upload_download.html
More complex APIs: Upload and Download Files with Flask — Faculty platform documentation
import requests API_URL = 'https://cube-64e0d7d8-1a3d-4fec-82da-fa7afea9138e.api.my.faculty.ai' API_KEY = 'i0cgsdYL3hpeOGkoGmA2TxzJ8LbbU1HpbkZo8B3kFG2bRKjx3V' headers = {'UserAPI-Key': API_KEY} response = requests.get('{}/files'.format(API_URL), headers=headers) response.json() >>> ['file1.txt', 'data.csv'] ... with open('newdata.csv') as fp: content = fp.read() response = requests.post( '{}/files/newdata.csv'.format(API_URL), headers=headers, data=content ) response.status_code >>> 201
🌐
Python Geeks
pythongeeks.org › python geeks › learn flask › file uploading with python flask
File Uploading with Python Flask - Python Geeks
May 19, 2023 - Inside the route function, we access the uploaded file using request.files[‘file’], where ‘file’ is the name of the file input field in the form. We then save the file to a directory on the server using the save() method, which takes the path where the file should be saved as an argument. In this example, we save the file in a directory called ‘uploads’ in the same directory as the Flask application.
🌐
The Teclado Blog
blog.teclado.com › file-uploads-with-flask
How to handle file uploads with Flask - The Teclado Blog
July 20, 2023 - To create this, we need a name for it and an iterable of allowed file extensions. The name is important, as we'll use it later. import secrets # built-in module from flask import Flask, flash, render_template, request, redirect, url_for from flask_uploads import IMAGES, UploadSet, configure_uploads app = Flask(__name__) photos = UploadSet("photos", IMAGES)
🌐
Stack Overflow
stackoverflow.com › questions › 59528484 › python3-flask-receive-file-and-send-it-to-another-api
python - Python3 flask receive file and send it to another api - Stack Overflow
@app.route('/file', methods=['POST']) def get_task_file(): response_obj = {} if 'file' not in request.files: abort(400) print(request.files["file"].filename) # TEXT EXTRACT url1 = 'http://localhost:5001/text/api' headers = {'Content-type': 'multipart/form-data'} print(type(request.files['file'])) r1 = requests.request("POST", url1, files={'file':request.files['file']}, headers=headers) print(r1.text) Right now the file type is <class 'werkzeug.datastructures.FileStorage'> and I am getting 400 errors. I just want to add that the logic on the second API is similar, should I change it? ... <class 'werkzeug.datastructures.FileStorage'> appears to be a thin wrapper around a file like object, and not the file itself. tedboy.github.io/flask/generated/generated/… Try request.files['file'].read()
🌐
Stack Overflow
stackoverflow.com › questions › 67006325 › how-to-process-files-from-request-in-flask
python - How to process files from request in Flask - Stack Overflow
app=Flask(__name__) @app.route('/process', methods=['GET', 'POST']) def post_data(): if request.method == "POST": files = request.files.getlist("file") for file in files: print(file.data) #.....do some processing return "" if __name__ == '__main__': app.run(host= '127.0.0.1', port= 5000)
🌐
GitHub
github.com › fabianlee › python-flask-upload-files › blob › master › flask_upload_files.py
python-flask-upload-files/flask_upload_files.py at master · fabianlee/python-flask-upload-files
# files will be materialized as soon as we touch request.files, # so check for errors right up front · try: flask.request.files ·
Author   fabianlee
Top answer
1 of 1
1

Short answer:

Don't specify a Content-Type in the headers dictionary, when providing a files argument to the requests.request method.

Longer answer

I tried to test that functionality to my own Flask upload script.

This worked when removing 'Content-Type': 'multipart/form-data' form the headers dictionary, otherwise the response was 400 bad request (see response.content)

I noted that after making the request, and inspecting response.request.headers I could see that

  • when specifying that header it was part of the request, as-is:

     'Content-Type': 'multipart/form-data'
    
  • however when not specifying it requests automatically generates the header with a boundary, and the request succeeded:

     'Content-Type': 'multipart/form-data; boundary=1beba22d28ce1e2cdcd76d253f8ef1fe'
    

Also:

  • To find the headers sent from curl, either by using the trace method or if you have access to the server, printing request.headers within the upload route, you can see that the curl command automatically appends a boundary to the header, even when the flag -H "Content-Type: multipart/form-data" is provided:

      Content-Type: multipart/form-data; boundary=------------------------c263b5b9297c78d3
    
  • The same can be observed via the Network tab in your browser dev-tools, when uploading via an HTML form with enctype="multipart/form-data" set as an attribute.


I had always thought that manually adding 'Content-Type:':'multipart/form-data' to the headers dict was required, but it appears when using the the files argument to requests.request method, this is automatically generated with the boundary.

In fact the requests docs make no mention of setting this header yourself.