413 Content Too Large
Request entity is larger than limits defined by the server.
Usually happens because:
- ☑ Uploading files that exceed server
- ☑ Sending extremely large JSON array
🔍 Quick Checklist:
Meaning
The HTTP 413 Content Too Large client error status code (formerly Payload Too Large) indicates that the request entity is larger than limits defined by the server; the server might close the connection or return a Retry-After header field.
Root Causes
- Uploading files that exceed server configuration limits (e.g. Nginx client_max_body_size).
- Sending extremely large JSON array batches to REST endpoints.
| Cause | Frequency |
|---|---|
| Uploading files that exceed server | ⭐⭐⭐⭐⭐ |
| Sending extremely large JSON array | ⭐⭐⭐⭐ |
Common Mistakes
- Setting backend application body limits higher than proxy (Nginx) limits (results in Nginx returning 413 before the app even receives it).
- Failing to handle 413 gracefully on the client UI, causing file upload animations to freeze.
How to Fix
Framework-Specific Examples
Setting body parser size limits in Express.
const express = require('express');
const app = express();
// Limit JSON payload body size to 1MB
app.use(express.json({ limit: '1mb' }));Server Configuration Examples
Increasing client max body size limit in Nginx.
server {
client_max_body_size 50M;
}Prevention
- Synchronize body size limits across reverse proxies, app gateways, and frameworks.
- Check file sizes on the client side using JavaScript before starting uploads.
Frequently Asked Questions (FAQ)
Q: What is the new name of 413 Payload Too Large?
In newer HTTP specifications, the name has been updated to '413 Content Too Large' to reflect that it applies to the body content size regardless of payload framing.
Q: How do I fix a 413 error in Nginx?
Add or increase the 'client_max_body_size' directive inside your nginx.conf server or location blocks (e.g. `client_max_body_size 10M;`).
Q: Can I return a Retry-After header with 413?
Yes, servers can include a 'Retry-After' header indicating when the client should try the transaction again.
Q: Should I use chunked uploads to prevent 413?
Yes. Splitting large files into 1MB-5MB chunks and uploading them sequentially is the best way to bypass server size constraints.