Tori Huang Tori Huang - 1 year ago 259
Node.js Question

How to send large csv in http post request

I have a very large CSV file I am trying to send from client to server, using MEAN stack. I keep getting this error saying I'm sending to much data at once.

Error: request entity too large

How do I send a large csv file from client to server with an http post request?

Answer Source

Note that in Express 4, instead of express.json() and express.urlencoded(), you must require the body-parser module and use its json() and urlencoded() methods, like so :

var bodyParser = require('body-parser');
app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true}));

If the extended option is not explicitly defined for bodyParser.urlencoded(), it will throw a warning (body-parser deprecated undefined extended: provide extended option). This is because this option will be required in the next version and not be optional anymore. For more info on the extended option, please refer to the readme of body-parser.

declare your parsers explicitely, like so :

app.use(express.json({limit: '50mb'}));
app.use(express.urlencoded({limit: '50mb'}));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download