413 Content Too Large
Fault: Client
TL;DR
Request payload exceeds server's size limits.
The request entity is larger than limits defined by the server.
What This Error Means
The request entity is larger than limits defined by the server.
Request payload exceeds server's size limits.
Common Causes
- File upload too large
- POST data exceeds limit
- Request body too big
How to Fix It (For Visitors)
- Upload smaller file
- Reduce data size
- Split into multiple requests
How to Fix It (For Developers/Admins)
- Increase client_max_body_size (Nginx)
- Increase LimitRequestBody (Apache)
- Increase upload_max_filesize (PHP)
- Implement chunked uploads
Code Examples
Here's how to return a 413 status code in various programming languages:
Python (Flask)
from flask import Flask, jsonify
app = Flask(__name__)
@app.route('/endpoint')
def endpoint():
return jsonify({"message": "Content Too Large"}), 413
Node.js (Express)
const express = require('express');
const app = express();
app.get('/endpoint', (req, res) => {
res.status(413).json({ message: 'Content Too Large' });
});
PHP
<?php
http_response_code(413);
header('Content-Type: application/json');
echo json_encode(['message' => 'Content Too Large']);
?>
Go
package main
import (
"encoding/json"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(413)
json.NewEncoder(w).Encode(map[string]string{
"message": "Content Too Large",
})
}
Java (Spring Boot)
@GetMapping("/endpoint")
public ResponseEntity<Map<String, String>> endpoint() {
Map<String, String> response = new HashMap<>();
response.put("message", "Content Too Large");
return ResponseEntity.status(413).body(response);
}
Ruby (Sinatra)
get '/endpoint' do
status 413
json message: 'Content Too Large'
end
Browser Compatibility
| Browser | Support | Notes |
|---|---|---|
| Chrome | ✓ Full Support | All versions |
| Firefox | ✓ Full Support | All versions |
| Safari | ✓ Full Support | All versions |
| Edge | ✓ Full Support | All versions |
Official Specification
This status code is defined in RFC 7231 Section 6.5.11.