Form data exceeding 1MB causes HTTP 400 errors since Starlette 0.40.0
warningconfigurationUpdated Nov 20, 2024(via Exa)
Sources
How to detect:
Since Starlette 0.40.0, form parameters exceeding the default 1024KB (1MB) limit trigger HTTP 400 errors with message 'Part exceeded maximum size of 1024KB.' This is due to the new max_part_size attribute in MultiPartParser introduced to resolve a security vulnerability.
Recommended action:
Override max_part_size by intercepting requests with middleware and calling request.form() with custom max_part_size parameter. Example: await request.form(max_part_size=50*1024*1024) for 50MB limit. Alternatively, create a custom request class or use a Depends function that returns FormData with custom limits. Avoid using BaseHTTPMiddleware as it causes form data loss.