NodeJS/Express Request Entity Too Large - Heroku

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

I've looked everywhere and can't seem to find an explanation about this, this is what Heroku is showing in my logs:

45:45+00:00 app[web.7]: Error: Request Entity Too Large 45:45+00:00 app[web.7]:     at Object.error (/app/node_modules/express/node_modules/connect/lib/utils.js:44:13) 45:45+00:00 app[web.7]:     at Object.limit [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/limit.js:45:47) 45:45+00:00 app[web.7]:     at next (/app/node_modules/express/node_modules/connect/lib/proto.js:190:15) 45:45+00:00 app[web.7]:     at Object.logger [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/logger.js:157:5) 45:45+00:00 app[web.7]:     at next (/app/node_modules/express/node_modules/connect/lib/proto.js:190:15) 45:45+00:00 app[web.7]:     at Object.favicon [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/favicon.js:78:7) 45:45+00:00 app[web.7]:     at next (/app/node_modules/express/node_modules/connect/lib/proto.js:190:15) 45:45+00:00 app[web.7]:     at Object.expressInit [as handle] (/app/node_modules/express/lib/middleware.js:31:5) 45:45+00:00 app[web.7]:     at next (/app/node_modules/express/node_modules/connect/lib/proto.js:190:15) 45:45+00:00 app[web.7]:     at Object.query [as handle] (/app/node_modules/express/node_modules/connect/lib/middleware/query.js:44:5) 45:45+00:00 app[web.7]: POST /mls 413 1ms - 980 

I've included the last log record because I'm not sure if it suggests the HTTP URL where these errors happened, or if it's the URL of the next request the Heroku dyno is processing (we receive hundreds of requests a second so it's a bit crazy to track).

My application (ExpressJS) requires receiving large POST requests, which is why I've put

app.use(express.limit('5mb')); 

at the top of the app to allow large post requests (usually less than 2MB). I'm not sure if the errors above are being caused by receiving a request that's too large or trying to send a request to S3 that's too large, or something else. Any ideas?

Thanks!

回答1:

if you are using Express v4+ you can use

app.use(bodyParser({limit: '5mb'})); 

but make sure this line is above

app.use(bodyParser.json()); 

otherwise it will not work



回答2:

I try to solved this problem in many ways but finally i got solution and solution is too easy solution , I just bypass code, Please follow following steps it will help you to solve the problem - open following page in your project

node_modules\body-parser\node_modules\raw-body\index.js

and change

if (typeof options.limit === 'number') limit = options.limit

just remove option.limit and add number, whatevr your limit eg. limit =10024



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