Skip to content

Python Workers: multipart/form-data body parsing fails at ~1 MB (undocumented limit) #6127

@rafaelqntn

Description

@rafaelqntn

Python Workers: multipart/form-data body parsing fails at ~1 MB (undocumented limit)

What version(s) of the runtime are you using?

Latest deploy target as of 2026-02-20 (compatibility_date = "2024-12-06", compatibility_flags = ["python_workers"]). Also reproducible locally with wrangler dev (wrangler 3.x).

What steps can reproduce the bug?

  1. Create a Python Worker that accepts a multipart/form-data file upload (e.g., via FastAPI UploadFile or raw Starlette multipart parsing).
  2. Upload a file <= 1024 KB — request reaches the Worker handler normally.
  3. Upload a file >= ~1040 KB — request fails before any application code executes.

Binary search confirms the threshold is between 1024 KB and 1040 KB.

Minimal repro using curl:

# Create a 1024 KB test file — succeeds (reaches app code, returns 401 auth error as expected)
dd if=/dev/urandom of=/tmp/test_1024k.bin bs=1024 count=1024
curl -s -o /dev/null -w "%{http_code}" \
  -F "file=@/tmp/test_1024k.bin;type=application/pdf" \
  https://<your-python-worker>/api/documents
# Returns: 401

# Create a 1040 KB test file — fails at body parsing layer
dd if=/dev/urandom of=/tmp/test_1040k.bin bs=1024 count=1040
curl -s -o /dev/null -w "%{http_code}" \
  -F "file=@/tmp/test_1040k.bin;type=application/pdf" \
  https://<your-python-worker>/api/documents
# Returns: 400 — "There was an error parsing the body"

What is the expected behavior?

Per the Workers platform limits documentation (https://developers.cloudflare.com/workers/platform/limits/#request-and-response-limits), the request body size limit is 100 MB on the Free/Pro plan. A ~1 MB multipart upload should succeed and be available to the Worker handler.

What do you see instead?

A 400 Bad Request response with body {"detail":"There was an error parsing the body"} is returned. The error originates from the multipart body parser layer (likely python-multipart / Starlette running under Pyodide in workerd), not from any application code — the Worker's fetch handler is never invoked.

Additional context

This only affects Python Workers. JavaScript/TypeScript Workers on the same account and zone handle the same files without issue (the 100 MB platform limit applies as documented).
The wrangler.jsonc configuration has no body-size-related settings, and the configuration reference (https://developers.cloudflare.com/workers/wrangler/configuration/) does not expose one. The limits key only supports cpu_ms and subrequests.
This limitation is not documented anywhere: not on the Limits page (https://developers.cloudflare.com/workers/platform/limits/), the Known Issues page (https://developers.cloudflare.com/workers/platform/known-issues/), or the Python Workers docs (https://developers.cloudflare.com/workers/languages/python/).
Our MAX_UPLOAD_SIZE_MB app-level env var is set to 10 (10 MB), but the validation code is never reached.
This blocks any real-world file upload use case in Python Workers (e.g., PDF processing, image uploads) for files larger than ~1 MB.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions