413 Payload Too Large Error
Fix 413 Payload Too Large errors when uploading files or sending large request bodies.
What Does This Error Mean?
The 413 Payload Too Large status code means the request body is larger than the server is willing or able to process. This commonly occurs during file uploads or when sending large JSON payloads.
Common Causes
File upload exceeds server size limit
JSON payload with deeply nested or massive data
Nginx client_max_body_size limit exceeded
PHP/Apache upload_max_filesize setting too low
AWS/Azure/GCP load balancer request size limits
Base64-encoded data expanding file size significantly
How to Fix It
Increase server upload limits
Configure the web server and application to allow larger request bodies.
# Nginx: increase body size limit
http {
client_max_body_size 50M;
}
# Express.js
app.use(express.json({ limit: "50mb" }))
app.use(express.urlencoded({ limit: "50mb", extended: true }))Use chunked uploads
Break large files into smaller chunks and upload them sequentially.
const CHUNK_SIZE = 1024 * 1024 // 1MB chunks
function uploadInChunks(file) {
for (let start = 0; start < file.size; start += CHUNK_SIZE) {
const chunk = file.slice(start, start + CHUNK_SIZE)
const formData = new FormData()
formData.append("chunk", chunk)
formData.append("index", start / CHUNK_SIZE)
formData.append("total", Math.ceil(file.size / CHUNK_SIZE))
await fetch("/api/upload", { method: "POST", body: formData })
}
}Compress before sending
Compress large payloads to reduce their size before transmission.
// Compress JSON before sending
async function sendCompressed(url, data) {
const blob = new Blob([JSON.stringify(data)])
const compressed = new CompressionStream("gzip")
// Send with Content-Encoding header
fetch(url, {
method: "POST",
headers: { "Content-Encoding": "gzip" },
body: blob
})
}Related Tools
Use these tools to debug and fix this error:
HTTP Status Code Reference
Searchable reference of all HTTP status codes with descriptions and use cases.
Image Optimizer
Compress images in your browser reducing file size without losing quality.
Image Compressor
Compress images with precise quality control. Reduce file size by adjusting quality, removing metadata, and more.
Related Errors
Other common errors in this category:
401 Unauthorized Error
Learn what a 401 Unauthorized error means, common causes, and how to fix authentication failures in your web applications.
403 Forbidden Error
Learn what 403 Forbidden means, how it differs from 401, and how to fix access denied errors in your applications.
404 Not Found Error
Learn what 404 Not Found means, common causes, and how to fix broken links and missing resources on your website or API.
429 Too Many Requests Error
Learn what 429 Too Many Requests means, how rate limiting works, and how to handle or avoid hitting API rate limits.