简体   繁体   中英

increase the limit of request for form-data in express.js

I am using Express and sending request as FORM-DATA

ERROR -

PayloadTooLargeError: request entity too large
at readStream (e:\MindfulSAS\myGit\hereiam-api\node_modules\raw-body\index.js:155:17)
at getRawBody (e:\MindfulSAS\myGit\hereiam-api\node_modules\raw-body\index.js:108:12)
at read (e:\MindfulSAS\myGit\hereiam-api\node_modules\body-parser\lib\read.js:77:3)
at jsonParser (e:\MindfulSAS\myGit\hereiam-api\node_modules\body-parser\lib\types\json.js:134:5)
at Layer.handle [as handle_request] (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:317:13)
at e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:284:7
at Function.process_params (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:335:12)
at next (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:275:10)
at expressInit (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\middleware\init.js:40:5)
at Layer.handle [as handle_request] (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:317:13)
at e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:284:7
at Function.process_params (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:335:12)
at next (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:275:10)
at query (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\middleware\query.js:45:5)
at Layer.handle [as handle_request] (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\layer.js:95:5)
at trim_prefix (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:317:13)
at e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:284:7
at Function.process_params (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:335:12)
at next (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:275:10)
at Function.handle (e:\MindfulSAS\myGit\hereiam-api\node_modules\express\lib\router\index.js:174:3)

is their any way to increase the limit of request for form-data ?

I think below may help you

var app = express();
app.use(bodyParser.urlencoded({limit: '50mb', extended: false}));
app.use(bodyParser.json({limit: '50mb'}));

Use Body Parser NPM : https://www.npmjs.com/package/body-parser

var bodyParser = require('body-parser');

 app.use(bodyParser.urlencoded({
  extended: true,
  limit: '50mb',
  parameterLimit: 100000
  }))

 app.use(bodyParser.json({
  limit: '50mb',
  parameterLimit: 100000
 }))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM