Reputation: 3347
I have tried to make a post request, to my node server, with a base64 encoded file.
I get a PayloadTooLargeError: request entity too large exception, so i went to extend the payload limit, by Express 4 convention
app.use(bodyParser.json({limit: '100mb'}));
app.use(bodyParser.urlencoded({limit: '100mb', extended: true}));
however the problem still occurs, can anybody help me on why?
here are my global variables
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false}))
app.use(bodyParser.json({limit: '100mb'}));
app.use(bodyParser.urlencoded({limit: '100mb', extended: true}));
Upvotes: 8
Views: 14864
Reputation: 544
In your code you have called twice to bodyParser.json() & bodyParser.urlencoded(), the problem is that the one with limit is after the calls without options, which defaults to 100kb. So when you POST something greater than 100kb that error will be thrown, since the first parser will not go to the next middleware.
You shouldn't call bodyParser[method] twice.
Depending on how you're posting the base64 string, you may want to use
app.use(myParser.text({ limit: '200mb' }));
Upvotes: 3
Reputation: 779
It beacuse you called the same bodyParser.[method] twice. Never do that. Refer this question - duplicate of this
Upvotes: 2
Reputation: 312
In your code:
app.use(bodyParser.json())
Should be not used without options. If no options, the default size I believe will be about 100 Kb.
You can pay attention to text
parameter below:
app.use(myParser.text({ limit: '200mb' }));
If you are using a last version of express, so it should be something like this:
app.use(bodyParser.json({limit: '50mb', extended: true}));
app.use(bodyParser.urlencoded({limit: "50mb", extended: true, parameterLimit:50000}));
app.use(bodyParser.text({ limit: '200mb' }));
Try adding also a flag parameterLimit
> 100000 or larger.
Upvotes: 5
Reputation: 33
This is worked for me set the 'type' in addition to the 'limit' for bodyparser
var app = express();
var jsonParser = bodyParser.json({limit:1024*1024*10, type:'application/json'});
var urlencodedParser = bodyParser.urlencoded({ extended:true,limit:1024*1024*10,type:'application/x-www-form-urlencoded' });
app.use(jsonParser);
app.use(urlencodedParser);
Upvotes: 1