FastAPI file uploads - File, UploadFile and form fields
Answer: Uploaded files are sent as form data. Declare a parameter as UploadFile to receive a spooled file. It is stored in memory up to a size limit, and after that limit it is stored on disk.
Examples
from fastapi import FastAPI, File, Form, UploadFile
app = FastAPI()
@app.post("/upload")
async def upload(file: UploadFile = File(), title: str = Form()):
data = await file.read()
return {"filename": file.filename, "content_type": file.content_type, "n": len(data), "title": title}
@app.post("/uploads")
async def uploads(files: list[UploadFile] = File()):
return [f.filename for f in files]
Rules
- Install
python-multipartfirst. MixFile()andForm()fields on the same path operation when needed. UploadFileprovides metadata such asfilenameandcontent_type.
See also
Claims
- id: C1 claim: Uploaded files are sent as form data. source: S1 evidence: "uploaded files are sent as \"form data\""
- id: C2 claim: A spooled file stays in memory up to a size limit. source: S2 evidence: "A file stored in memory up to a maximum size limit"
- id: C3 claim: The files are uploaded as form data. source: S2 evidence: "The files will be uploaded as \"form data\""
Sources
- [S1] Request Files. FastAPI docs. https://fastapi.tiangolo.com/tutorial/request-files/ . License: MIT. Accessed 2026-11-18.
- [S2] tutorial/request-files.md. fastapi/fastapi (GitHub). https://github.com/fastapi/fastapi/blob/master/docs/en/docs/tutorial/request-files.md . License: MIT. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: FastAPI docs, Request Files; fastapi/fastapi (GitHub), tutorial/request-files.md. MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright FastAPI contributors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: FastAPI docs, Request Files; fastapi/fastapi (GitHub), tutorial/request-files.md. MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright FastAPI contributors.
Cite this
iinventedlight. 2026. "FastAPI file uploads - File, UploadFile and form fields." iinventedlight Library, iil:note:809nf1wz, version of 2026-11-18. https://iinventedlight.com/library/notes/fastapi-uploads/. License: CC-BY-4.0.
@misc{iil_note_809nf1wz,
author = {{iinventedlight}},
title = {{FastAPI file uploads - File, UploadFile and form fields}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/fastapi-uploads/},
note = {Permanent ID iil:note:809nf1wz. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/fastapi-uploads.md.