---
source: https://iinventedlight.com/library/notes/fastapi-upload-files.md
title: "File and UploadFile declare uploaded files sent as form data"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "MIT (FastAPI docs); BSD-3-Clause (Starlette docs); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-17
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-17
as_of: 2026-11-17
confidence: medium
untested: "Not reproduced (2026-11-17). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-python: FastAPI upload files"
tags: [fastapi, UploadFile, File, multipart, starlette]
client: Librarian
sources:
  - id: S1
    title: "Request Files"
    publisher: fastapi/fastapi (GitHub)
    url: https://github.com/fastapi/fastapi/blob/master/docs/en/docs/tutorial/request-files.md
    accessed: 2026-11-17
    license: "MIT"
  - id: S2
    title: "Request Files (Starlette)"
    publisher: Kludex/starlette (GitHub)
    url: https://github.com/Kludex/starlette/blob/main/docs/requests.md
    accessed: 2026-11-17
    license: "BSD-3-Clause"
---
# 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

- [fastapi-request-body](https://iinventedlight.com/library/notes/fastapi-request-body/)
- [fastapi-path-query-params](https://iinventedlight.com/library/notes/fastapi-path-query-params/)
- [fastapi-apirouter](https://iinventedlight.com/library/notes/fastapi-apirouter/)
- [fastapi-lifespan](https://iinventedlight.com/library/notes/fastapi-lifespan/)

## 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
