An HTTP 413 error means a server refuses a request because its content exceeds a size it will process. To fix it, identify which layer rejected the body, compare that limit with your upload contract, and either reduce the payload or adjust the specific limit you own. A working page and a small successful upload do not prove that the advertised maximum works.
The current name is 413 Content Too Large. Older messages include 413 Payload Too Large and Request Entity Too Large. They describe the same status code. MDN status reference
For developers shipping a student portfolio, document importer, or contact form with attachments, the useful result is concrete: supported files succeed, oversized requests fail clearly, and the visitor can correct the problem without losing the rest of the form.
Diagnose an HTTP 413 error from one failed upload
Open the browser Network panel, preserve the log, and submit one disposable test file to an endpoint you control. Record the URL, method, status, response headers, content type, request size information, and release identifier. Keep private files and credentials out of screenshots and tickets.
Compare a small accepted request with the failing request. Keep the route, authentication, and file type the same while varying size. A repeatable size boundary is more useful evidence than “uploads sometimes fail.”
Look for these clues:
- An HTML error page arrives instead of the application's usual JSON response.
- The edge or reverse-proxy log records a rejection, while the application has no matching request.
- A request succeeds through the local development server but fails through the public hostname.
- Several individually acceptable files fail when submitted together.
These clues narrow the investigation; an error-page logo or Server header alone does not prove which component generated the response. Correlate timestamps or request IDs across the layers you can inspect.
Separate other failures first. A 405 concerns the method, a 429 concerns request rate, and a timeout may occur without any 413 response. The JavaScript console errors workflow explains how to connect browser messages with the original request.
Find the smallest request-body limit in the path
List the actual upload path: browser, CDN or gateway, reverse proxy, framework body parser, multipart handler, and storage integration. Record the configured limit and owner at each layer. The first layer that rejects the request prevents downstream code from handling it.
Do not assume a deployment platform has the same allowance as your local server. Check its current documentation for your product and plan. A fixed upstream cap cannot be raised by editing the application's parser configuration.
Define the units before changing a setting. For example, a product might allow one PDF up to 5 MiB, meaning 5,242,880 bytes, while allowing a somewhat larger total multipart body. A decimal 5 MB limit is 5,000,000 bytes. Publish the limit that the server actually enforces.
A file limit and a request-body limit measure different things. Multipart bodies include boundaries, field names, filenames, and other form values. Multiple files add together. A raw JSON limit applies to the encoded JSON body; embedding a file as text also changes the size. Test the representation your frontend really sends.
Fix an Nginx limit at the right scope
If logs identify Nginx as the rejecting layer, inspect the effective client_max_body_size for the matched route. The directive is allowed in http, server, and location contexts and returns 413 when the request body exceeds its configured limit. Nginx directive reference
For an existing upload location, an illustrative configuration is:
location /api/uploads {
client_max_body_size 6m;
proxy_pass http://upload_backend;
}
Here upload_backend represents an upstream you have already defined. Integrate the directive into the location that actually handles the upload; do not paste a competing location into an unfamiliar configuration. Validate the configuration with nginx -t, then reload through your deployment process.
This example leaves room around a 5 MiB file contract, but it does not establish that file limit in the application. Enforce file count, per-file bytes, total bytes, and allowed content on the server too. Raising Nginx's limit leaves any smaller gateway or parser cap in effect.
Choose a bounded allowance based on the task. Disabling size checks or granting every endpoint a large body allowance adds resource exposure without explaining the original failure.
Return useful upload recovery instead of a JSON parse error
The browser should show the allowed size beside a labeled file input before submission. The HTML accept attribute helps the file picker suggest file types; it does not enforce a byte limit or replace server validation. MDN file input reference
For a multipart upload built with FormData, let the browser generate the Content-Type header and boundary. Manually setting it to multipart/form-data can leave out the boundary needed to parse the body. MDN FormData guidance
Check the status before assuming every response is JSON. An upstream proxy can return an HTML 413 page even when your application normally returns a JSON error. For example, adapt this request helper to your form:
async function uploadDocument(form, send = fetch) {
const response = await send('/api/uploads', {
method: 'POST',
body: new FormData(form),
});
if (response.status === 413) {
throw new Error('Choose one PDF no larger than 5 MiB, then try again.');
}
if (!response.ok) {
throw new Error(`Upload failed (${response.status}). Please try again.`);
}
return response;
}
This helper assumes the stated one-PDF policy is enforced by your server. Its caller must catch the error, display it as text, restore the submit control, and preserve unrelated field values. Only reset the form after the endpoint's documented success result. fetch() resolves for HTTP error responses, so inspect the status; transport failures require their own catch path. MDN Fetch error handling
Follow the accessible form errors tutorial to connect the message to the field and provide a keyboard recovery path. If a cross-origin error is hidden by CORS, inspect the gateway's error-response policy as well; application middleware cannot modify a response that never reaches the application.
Avoid repeatedly sending the unchanged oversized body. RFC 9110 permits a server to stop receiving it or close the connection. For a temporary condition, it recommends Retry-After; a permanent file-size policy normally requires a smaller payload or an approved alternative upload path. HTTP semantics for status 413
Add an HTTP 413 error boundary check before release
Test below, at, and above each promised boundary. For multipart uploads, use valid fixtures and the real field name. For example, on a disposable test endpoint:
curl --silent --show-error --max-time 30 \
--dump-header upload-headers.txt --output upload-response.txt \
--form 'document=@./fixtures/over-limit.pdf;type=application/pdf' \
https://example.com/api/uploads
Replace the URL and fixture with your own test setup. This POST may create a record if accepted; arrange cleanup. Inspect the status and saved response without printing private payloads. Test multipart through the public routing layers as well as directly against your application.
A small Node.js check can separately lock down an exact raw-body limit. Save this as check-upload-limit.mjs; it requires an endpoint designed to accept disposable application/octet-stream bodies, with an inclusive 1,024-byte limit and a 204 success response. These are an example contract, not defaults for your service.
import assert from 'node:assert/strict';
const target = process.env.UPLOAD_TEST_URL;
assert.ok(target, 'Set UPLOAD_TEST_URL to your disposable upload endpoint');
for (const [bytes, expected] of [[1023, 204], [1024, 204], [1025, 413]]) {
const response = await fetch(target, {
method: 'POST',
redirect: 'manual',
headers: { 'Content-Type': 'application/octet-stream' },
body: new Uint8Array(bytes),
signal: AbortSignal.timeout(5000),
});
try {
assert.equal(response.status, expected, `${bytes} bytes: wrong status`);
} finally {
await response.body?.cancel();
}
}
console.log('Raw upload size boundaries passed');
Run with UPLOAD_TEST_URL set to your controlled endpoint. Redirects remain visible so a login redirect cannot look like upload success. A connection closure fails this particular 413-response contract; it does not contradict the HTTP specification. The test also catches a 200 HTML fallback instead of the expected result.
Raw-body checks do not validate multipart overhead, file contents, browser feedback, or storage. Add those cases to the website form testing checklist: the largest valid file, one byte over the per-file limit, too many files, total-body overflow, and a smaller replacement after rejection. Confirm the rejected attempt creates no partial record or orphaned object. Keep the test and cleanup in your website regression testing routine.
Check the surrounding public page with Slop Audit
Once upload recovery works, run Slop Audit on the public page containing the form. Its implemented checks cover public-page reachability, metadata, and, when the browser stage completes, form-label and axe accessibility evidence plus bounded layout and runtime observations. Fix the observed findings and rescan the same route.
Slop Audit does not upload files, exercise size boundaries, submit forms, or verify storage cleanup. Keep the upload tests alongside its report. The combined release record should name the enforced limits, the rejecting layer, the boundary results, and the corrected user path.