413 Request Entity Too Large (Payload Too Large): what it means and how to fix it

A file upload or a big JSON POST fails with 413, while small ones work. Something between the browser and your code has a size limit, and your request is over it.

Find the layer that said no

What the 413 looks likeWho sent itDefault limit
HTML page "413 Request Entity Too Large" with nginx at the bottomnginx1 MB
PayloadTooLargeError: request entity too large in the Node logExpress body-parser / express.json()100 KB
Cloudflare-branded 413Cloudflare100 MB on Free and Pro, 200 MB Business, 500 MB Enterprise
Laravel PostTooLargeException, or empty $_POST/$_FILESPHPpost_max_size 8M, upload_max_filesize 2M
Django RequestDataTooBigDjangoDATA_UPLOAD_MAX_MEMORY_SIZE 2.5 MB (form data, not file uploads)
IIS 413 or 404.13IISmaxAllowedContentLength about 28.6 MB
AWS API Gateway or Lambda errorAWS10 MB API Gateway; 6 MB synchronous Lambda payload

Check the response headers in DevTools: server: nginx or server: cloudflare tells you a lot. If the app's own logs never show the request, a proxy in front stopped it.

Fixes by layer

# nginx (http, server or location block), then: nginx -t && systemctl reload nginx
client_max_body_size 50m;     # 0 disables the check

// Express
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ limit: '10mb', extended: true }));

; PHP (php.ini), then restart PHP-FPM
upload_max_filesize = 50M
post_max_size = 55M          ; must be larger than upload_max_filesize

# Django settings.py
DATA_UPLOAD_MAX_MEMORY_SIZE = 10 * 1024 * 1024

On Kubernetes with ingress-nginx, set the annotation nginx.ingress.kubernetes.io/proxy-body-size: 50m. In Next.js API routes, set export const config = { api: { bodyParser: { sizeLimit: '10mb' } } }; server actions use serverActions.bodySizeLimit in next.config.js (default 1 MB).

Units trip people up

nginx 1m means 1 MiB (1,048,576 bytes). Base64 makes data about 33% bigger, so a 4 MB image sent as a Base64 string in JSON is roughly 5.3 MB on the wire, and a multipart upload adds a little framing on top. The Base64 tool shows the size before and after; the number converter helps with bytes versus hex lengths.

Better than raising the limit forever

Related

431 Request Header Fields Too Large (headers, not the body) · 502 Bad Gateway · Base64 data URLs · ENOSPC no space left on device

Questions

What does 413 Request Entity Too Large mean?

The request body, usually a file upload or large JSON, is bigger than a size limit set by the web server, a proxy or your framework.

How do I fix 413 in nginx?

Set client_max_body_size to the size you need (for example 50m) in the http, server or location block, then test the config and reload nginx.

Why do I get PayloadTooLargeError in Express?

express.json() and body-parser default to 100 KB. Pass a larger limit, such as express.json({ limit: '10mb' }).

What is Cloudflare's upload limit?

100 MB per request on the Free and Pro plans. Larger files need chunked uploads or a direct upload to storage.

Is 413 the same as 431?

No. 413 is about the request body; 431 means the headers, usually cookies, are too large.

Published .

Try it

Related guides

Newest guides