Error Encyclopedia
413

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

1

File upload exceeds server size limit

2

JSON payload with deeply nested or massive data

3

Nginx client_max_body_size limit exceeded

4

PHP/Apache upload_max_filesize setting too low

5

AWS/Azure/GCP load balancer request size limits

6

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:

Related Errors

Other common errors in this category: