Node.js error: too many parameters Error loading bulk data

I have a task for loading user data in bulk through a csv file. I am using nodejs and express frameworks. When I send a csv file from 60 to 70 lines, it works fine, but when it exceeds 70 lines, it starts to give too many parameters to the server error. After some research, I came to the conclusion that this may be a problem with the size of the body parser, so I tried this blog , but it did not work, the error is still the same.

here is my code for the body parser:

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

Error message:

 2016-04-19T10:29:45.299Z - error: [req#d3a1fa1a-278e-496e-9cb1-b3a944e3d1c8/app] [App] Error: too many parameters Error: too many parameters at queryparse (d:\Git\gap-vm 13416\node_modules\body-parser\lib\types\urlencoded.js:119:17) at parse (d:\Git\gap-vm 13416\node_modules\body-parser\lib\types\urlencoded.js:64:9) at d:\Git\gap-vm 13416\node_modules\body-parser\lib\read.js:91:18 at IncomingMessage.onEnd (d:\Git\gap-vm 13416\node_modules\raw-body\index.js:136:7) at IncomingMessage.g (events.js:273:16) at emitNone (events.js:80:13) at IncomingMessage.emit (events.js:179:7) at endReadableNT (_stream_readable.js:906:12) at nextTickCallbackWith2Args (node.js:474:9) at process._tickCallback (node.js:388:17) 

So can anyone tell me where I am going wrong. Any suggestion would be helpful. Thanx in advance.

+7
javascript body-parser
source share
3 answers

As others mention, you need to set parameterLimit to handle the "too many parameters" error. You may also need to set the limit to a larger size to avoid loading size errors. In the case of CSV, urlencoded restrictions apply, but others may also want to set JSON limits. The following setting will work if there are no other places in the code that override these parameters:

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

In your code, you are not using parameterLimit at all, as indicated on the blog you provided.

 var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: false, parameterLimit: 1000000 // experiment with this parameter and tweak })); 
+5
source share

I'm not sure where you guys are testing your API, but for me it was because I set the Content-Type header to application/x-www-form-urlencoded in Postman. As soon as I removed the header and used form-data in the body section, it solved the problem. Be sure to always use form-data when uploading files. Hope this helps ...

+4
source share

All Articles