Learning center

An upload fails with 413: the proxy's limit or the application's

A 413 Content Too Large response means something refused the request because its body was too big. Between the browser and the application there are often two or three layers with their own limit: a CDN, a load balancer, a reverse proxy and the application framework. The response's headers and body usually say which layer answered, and a cross-origin upload can hide the status from the page entirely.

The page may not see the 413 at all#

We served a fixture where a stand-in for nginx refused any body over 1 MiB with nginx's HTML error page and no CORS headers, and posted 2 MiB from a page with fetch.

UploadWhat the page's fetch saw
Same originstatus 413, Content-Type: text/html
Cross-origin, to an API on another originTypeError: Failed to fetch

The cross-origin response had no Access-Control-Allow-Origin header, because the proxy wrote it, not the application that normally adds CORS headers. The browser withheld the response from the page, so the app's error handling saw a network error and may have shown "Check your connection". The Network panel still shows the 413. CORS error or server error covers that pattern.

Find the layer that answered#

Read the 413 response in the Network panel:

SignalPoints to
HTML body with <center>nginx</center>, or a Server: nginx headerAn nginx proxy. Its client_max_body_size defaults to 1 MiB.
A CDN-branded error page, or the CDN's request ID header and no application headersThe CDN or edge
A JSON body in the application's error format, or the app's own request ID headerThe application or its framework
No response, and net::ERR_CONNECTION_RESET or similarA layer that closed the connection while the body was still being sent

nginx: client_max_body_size ยท MDN: 413 Content Too Large

Replay with controlled sizes#

Find the limit with a file of a known size, sent the same way the browser sends it. Copy the upload request with Copy as cURL from the Network panel, replace the file with a generated one, and change only the size:

head -c 1048000 /dev/urandom > under.bin    # just under 1 MiB
head -c 1049000 /dev/urandom > over.bin     # just over 1 MiB
curl -sS -o /dev/null -w '%{http_code}\n' -F 'file=@under.bin' -H 'Authorization: Bearer TEST_TOKEN' https://staging.example.test/api/upload
curl -sS -o /dev/null -w '%{http_code}\n' -F 'file=@over.bin'  -H 'Authorization: Bearer TEST_TOKEN' https://staging.example.test/api/upload

A step between 200 and 413 at a round number such as 1 MiB, 10 MB or 100 MB usually matches a configured limit at one layer. The multipart encoding adds a few hundred bytes to the body, so the step sits just below the file size you would expect. Replay the request outside the page covers editing the copied command.

To isolate a layer, send the same request to the next layer in, such as the load balancer's address or the application's internal URL in a staging environment. The first layer that accepts the body is behind the one that refused it.

Report the size the browser sent#

The file's size on disk is not always the size of the request. Image uploads resized or re-encoded in the browser, base64-encoded JSON bodies (about four thirds of the original size) and multipart overhead all change it. Put the request's Content-Length from the Network panel in the report, with the file's size.

Worked example: uploads that failed with "offline"#

This example is fictional. Users report that attaching photos over about 1 MB shows "You appear to be offline". Smaller photos work. The API is at api.example.test and the app at app.example.test.

The Network panel shows the upload's response as 413 with nginx's HTML page and no CORS headers. The app's fetch received a TypeError, which its error handler mapped to the offline message. Replaying with curl at 1,048,000 and 1,049,000 bytes gave 200 and 413. The ingress proxy in front of the API still used the 1 MiB default. Two fixes followed: raising the proxy limit to match the application's 20 MB, and making the proxy add CORS headers to its own error responses so the app could show the real reason.

Questions#

Can the limit be in the browser?

Browsers do not impose a small limit on request bodies. Client-side code can, such as a check before upload or a library's chunk size, and its message is the app's own.

Why did the upload fail after a long wait?

Some layers read the whole body before rejecting it, and some reject after the headers arrive. A slow upload of a large file can spend minutes sending a body that will be refused. The time to the response, in the Network panel's Timing tab, shows which.

Does a chunked or resumable upload avoid the limit?

It can, because each request stays under the limit. Each chunk is still a request through the same layers, so the chunk size must fit the smallest limit.

Return to reproducing what someone else saw for the other layers a replay needs.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading