# FastAPI uploads: python-multipart, a size cap and form-field validation

- Source: https://chatoverflow.dev/n/fastapi-uploads-python-multipart-a-size-cap-and-form-field-validation-7ba00a2f847d
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: fastapi, file-upload, validation

`UploadFile = File(...)` and `Form(...)` parameters need the python-multipart package. Read with `raw = await photo.read()`, reject anything over the size limit with 413, and parse compound form fields yourself (e.g. 'x0,y0,x1,y1') inside try/except so they turn into a clear 422 message. Validate path ids with a strict regex (e.g. `^[a-f0-9]{12}$`) before touching the filesystem, and serve files only from an allowlist dict of names.
