Skip to content

Instantly share code, notes, and snippets.

@Maqsim
Last active April 30, 2024 20:36
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save Maqsim/857a14a4909607be13d6810540d1b04f to your computer and use it in GitHub Desktop.
Save Maqsim/857a14a4909607be13d6810540d1b04f to your computer and use it in GitHub Desktop.
HOW TO FIX "413 Payload too large" in NodeJS (Express)
const express = require('express');
const bodyParser = require('body-parser');
...
// Express 4.0
app.use(bodyParser.json({ limit: '10mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit: '10mb' }));
// Express 3.0
app.use(express.json({ limit: '10mb' }));
app.use(express.urlencoded({ limit: '10mb' }));
...
@ankuj
Copy link

ankuj commented Mar 9, 2019

Thanks this answer saved me! :)

@sarialon
Copy link

sarialon commented Apr 7, 2019

Thanks a lot for this answer

@ajordaan
Copy link

ajordaan commented May 2, 2019

Worked perfectly thank you

@Octubre13
Copy link

A lot of thanks for your help.

@Celtak
Copy link

Celtak commented Jun 7, 2019

Thanks!

@arknile
Copy link

arknile commented Jul 21, 2019

Many thanks. Simple and effective.

@Eddy118
Copy link

Eddy118 commented Jul 29, 2019

I Have used this Method to save High Quality images but When I save the Images and try to get them I am getting no response from the server.

@Maqsim
Copy link
Author

Maqsim commented Jul 29, 2019

I Have used this Method to save High Quality images but When I save the Images and try to get them I am getting no response from the server.

@Eddy118 Is it saving correctly to file-system/DB?

@sheosagar
Copy link

Thanks,
Also, it works for me.

@manonironside
Copy link

This worked for me, too! Are there any potential downsides to keep in mind in increasing this limit?

@matheusopedro
Copy link

Worked for as well! I'll be forever thankful!

@Milipeedo
Copy link

Thank you! works perfectly.Really Grateful to you since I'm new to this js language. It would have been really difficult to figure out how to fix it.

@united-forever
Copy link

Thanks bro!

@Mea-amor
Copy link

Thanks for that code my friend, you help me

@mlockett42
Copy link

mlockett42 commented Jan 15, 2022

@manonironside One potential downside is if untrusted users can submit to this end point it can be used by attackers to run denial of service attacks that exhaust the server's available memory

@KirillGoorevich
Copy link

I had this in my code:
app.use(express.json());
and I couldn't figure out why it didn't work then I tried this specific order:
const bodyParser = require('body-parser');
app.use(bodyParser.json({ limit: '10mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit: '10mb' }));
app.use(express.json());
and now it works.
why?

@tepaseointenso
Copy link

I had this in my code:
app.use(express.json());
and I couldn't figure out why it didn't work then I tried this specific order:
const bodyParser = require('body-parser');
app.use(bodyParser.json({ limit: '10mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit: '10mb' }));
app.use(express.json());
and now it works.
why?

i have the same problem

@ilorwork
Copy link

FYI:
you have to put those lines before
app.use(express.json());

Copy link

ghost commented Nov 6, 2022

Thank For sharing this

@DanielKomlaElijah
Copy link

This also worked for me. Thanks for sharing....

@milton-imageline
Copy link

+1

@Jsonlm
Copy link

Jsonlm commented May 8, 2023

Thanks a lot your answer helps a lot!!

@SwatiRanjangit
Copy link

Thanks a lot..now i'm able to upload it.

@QuocZuong
Copy link

+1 Siuuuuuuuuu

@danieltroger
Copy link

Thanks!

@zaadevofc
Copy link

not work :(

error:

413: PAYLOAD_TOO_LARGE
Code: FUNCTION_PAYLOAD_TOO_LARGE

this my code :

app.use(bodyParser.json({ limit: '100mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit: '100mb' }));
app.use(express.json());

@Shahtaymur
Copy link

FYI: you have to put those lines before app.use(express.json());

this worked for me.. 👍

@Rahad23
Copy link

Rahad23 commented Mar 18, 2024

not work :(

error:

413: PAYLOAD_TOO_LARGE
Code: FUNCTION_PAYLOAD_TOO_LARGE

this my code :

app.use(bodyParser.json({ limit: '100mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit: '100mb' }));
app.use(express.json());

How did you solve later?

@Elphaid
Copy link

Elphaid commented Apr 30, 2024

FYI: you have to put those lines before app.use(express.json());

It works

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment