File and UploadFile declare uploaded files sent as form data
Answer: Declare uploaded files with File or UploadFile. They arrive as form data, not JSON. Install python-multipart first. If the parameter type is bytes, FastAPI reads the file and you receive the contents as bytes. The whole contents will be stored in memory, which will work well for small files. UploadFile will work well for large files without consuming all the memory.
UploadFile
UploadFile uses a spooled file. Contents stay in memory up to a size limit, then the file is stored on disk. It has filename, content_type, and a file object that is a SpooledTemporaryFile. The async methods read, write, seek, and close must be awaited. In a plain def path operation you can call methods on .file directly.
FastAPI's UploadFile inherits from Starlette's UploadFile. Forms that include files are encoded as multipart/form-data. You can declare several File and Form fields, but you cannot also expect a JSON Body on the same request.
Starlette form uploads
In Starlette, request files also arrive as multipart form data. request.form() yields a FormData multidict that holds both text fields and uploads. Each upload is a UploadFile with filename, content_type, and a spooled file object. Await read() to get the contents.
See also
Claims
- id: C1 claim: Uploaded files are sent as form data. source: S1 evidence: "The files will be uploaded as \"form data\"."
- id: C2 claim: UploadFile uses a spooled file that can spill from memory to disk. source: S1 evidence: "A file stored in memory up to a maximum size limit"
- id: C3 claim: Request files are normally sent as multipart form data. source: S2 evidence: "sent as multipart form data (
multipart/form-data)"
- id: C4 claim: Starlette represents each uploaded file as an UploadFile. source: S2 evidence: "File upload items are represented as instances of"
Sources
- [S1] Request Files. fastapi/fastapi (GitHub). https://github.com/fastapi/fastapi/blob/master/docs/en/docs/tutorial/request-files.md . License: MIT. Accessed 2026-11-17.
- [S2] Request Files (Starlette). Kludex/starlette (GitHub). https://github.com/Kludex/starlette/blob/main/docs/requests.md . License: BSD-3-Clause. Accessed 2026-11-17.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: fastapi/fastapi (GitHub), Request Files, MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright (c) 2018 Sebastián Ramírez; Kludex/starlette (GitHub), Request Files (Starlette), BSD-3-Clause (https://raw.githubusercontent.com/Kludex/starlette/main/LICENSE.md). Copyright (c) 2018, Encode OSS Ltd. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: fastapi/fastapi (GitHub), Request Files, MIT (https://raw.githubusercontent.com/fastapi/fastapi/master/LICENSE). Copyright (c) 2018 Sebastián Ramírez; Kludex/starlette (GitHub), Request Files (Starlette), BSD-3-Clause (https://raw.githubusercontent.com/Kludex/starlette/main/LICENSE.md). Copyright (c) 2018, Encode OSS Ltd.
Cite this
iinventedlight. 2026. "File and UploadFile declare uploaded files sent as form data." iinventedlight Library, iil:note:abxxe7qx, version of 2026-11-17. https://iinventedlight.com/library/notes/fastapi-upload-files/. License: CC-BY-4.0.
@misc{iil_note_abxxe7qx,
author = {{iinventedlight}},
title = {{File and UploadFile declare uploaded files sent as form data}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-17},
url = {https://iinventedlight.com/library/notes/fastapi-upload-files/},
note = {Permanent ID iil:note:abxxe7qx. 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-upload-files.md.