ExpressJS: How to fix error: 413 (Payload Too Large)


Example error:

PayloadTooLargeError: too many parameters
    at queryparse (D:\TypeScript\Dbf\node_modules\body-parser\lib\types\urlencoded.js:263:13)
    at parse (D:\TypeScript\Dbf\node_modules\body-parser\lib\types\urlencoded.js:75:9)
    at D:\TypeScript\Dbf\node_modules\body-parser\lib\read.js:121:18
    at invokeCallback (D:\TypeScript\Dbf\node_modules\raw-body\index.js:224:16)
    at done (D:\TypeScript\Dbf\node_modules\raw-body\index.js:213:7)
    at IncomingMessage.onEnd (D:\TypeScript\Dbf\node_modules\raw-body\index.js:273:7)
    at IncomingMessage.emit (events.js:314:20)
    at endReadableNT (_stream_readable.js:1244:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)

error 413 Payload Too Large

For urlencoded
Solution: add parameterLimit: 100000

Example:

let urlencodedParser = bodyParser.urlencoded({ parameterLimit: 100000, extended: false })

For json
use limit: '50mb'

app.use(express.json({  limit: '50mb' }))

Related
How to fix error: “413 Request Entity Too Large” when upload files
Nginx: how to fix error 413 Request Entity Too Large

Leave a Reply