Setting Starlette's max part size for form data #12961
-
First Check
Commit to Help
Example Codefrom fastapi import FastAPI
app = FastAPI()
@app.put("/upload")
async def upload_document(content: Annotated[str, Form()]):
# Do anything with `content`
passDescription
Of course, this is intended behaviour. What I would like to know is how we can change the value of Thanks! Operating SystemLinux Operating System DetailsNo response FastAPI Version0.115.5 Pydantic Version2.9.1 Python Version3.10 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 13 replies
-
|
Hi there! 👋 Is there any special reason to use a form data with more than 1024kb? Seeing your endpoint definition as Otherwise, can you share with us more details? So we can then seek a better solution 🚀 |
Beta Was this translation helpful? Give feedback.
-
|
final my usage is |
Beta Was this translation helpful? Give feedback.
-
|
According to the source code, this should be a bug. Although parameters are set, the default parameters are always overwritten And there is no place to pass on references either |
Beta Was this translation helpful? Give feedback.





Hello @armant,
Since Starlette has introduced parameters to control form parsing options:
max_files,max_fields, andmax_part_size. It's now possible to intercept the request with a middleware and call request.form() with the desired options.Parsed form data is computed only once (and cached), so you won’t encounter any issues later when accessing the form through FastAPI.
The advantage of this approach is that you can control the size of each form dynamically, based on the incoming request.
That said, there's no doubt we should have a way to control these parameters globally.