Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Express.js bodyParser POST limit

I'm trying to set the limit option for bodyParser.urlencodedParser as my POST data is bigger than the default value. My code currently looks like the following but whatever i try i always receive the following error:

Error: request entity too large

var express = require('express');
var router = express.Router();
var jsonfile = require('jsonfile');
var bodyParser = require('body-parser');

var urlencodedParser = bodyParser.urlencoded({limit: '5mb'});

router.post('/data', urlencodedParser ,function(req, res) {


    if(typeof req.body.data === 'undefined')
    {
       console.log('Missing data');
       res.status(500).send({ error: 'Missing Data Parameters' });
       return;
    }

    // Static return value
    var output = [ 
        {"f" : "1"},
        {"f" : "2"},
        {"f" : "3"}
    ];

    res.send(output);
}

Any help greatly appreciated.

like image 310
scgy Avatar asked Aug 12 '15 13:08

scgy


1 Answers

I was having trouble sending image data over ajax and getting 'Error: request entity too large', managed to solve it by adding

app.use(bodyParser.json({limit: '50mb', type: 'application/json'}));

but the most important part was to make sure that i called

app.use(bodyParser());

after i set the limit, hope this helps!!

like image 121
Matt Avatar answered Oct 02 '22 02:10

Matt