mean.io - Error: 'Request entity too large'. How to increase bodyParser limit outside meanio module?

三世轮回 提交于 2019-12-10 03:59:57

问题


I am receiving following error with mean.io application.

Error: request entity too large

To overcome this issue, I have increased the bodyParser limit with in meanio module at following location.

node_modules/meanio/lib/core_modules/server/ExpressEngine.js

// Request body parsing middleware should be above methodOverride
  this.app.use(expressValidator());
  this.app.use(bodyParser.json({limit: '50mb'}));
  
  this.app.use(bodyParser.urlencoded({
    limit: '50mb',
    extended: true
  }));
  this.app.use(methodOverride());

However this is a bad practice and the changes will be lost if we upgrade the module. Can anyone suggest any alternative way to increase request limit at meanio app?


回答1:


I got this working actually it is the issue with npm meanio module in the latest version they have updated the code. You need to update the npm meanio package.After that you can able to overide the methods that are present in ExpressEngine.js file.

There is a issue opened for this on github https://github.com/linnovate/mean/issues/1169

After this they have fixed this issue and merged the code




回答2:


Try to apply this in your app.js instead.

app.use(bodyParser.json({limit: '50mb'}));
app.use(bodyParser.urlencoded({limit: '50mb'}));

Hope this help!




回答3:


2016, none of the above worked for me until i explicity set the 'type' in addition to the 'limit' for bodyparser, example: var bodyParser = require('body-parser');

  var app = express();
  var jsonParser       = bodyParser.json({limit:1024*1024*20, type:'application/json'});
  var urlencodedParser = bodyParser.urlencoded({ extended:true,limit:1024*1024*20,type:'application/x-www-form-urlencoding' })

  app.use(jsonParser);
  app.use(urlencodedParser);



回答4:


What I got to work was putting those two lines directly var app = express(); like so:

```

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

```



来源:https://stackoverflow.com/questions/29939852/mean-io-error-request-entity-too-large-how-to-increase-bodyparser-limit-ou

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!