NodeJS / Express请求实体太大 - Heroku [英] NodeJS/Express Request Entity Too Large - Heroku

查看:171
本文介绍了NodeJS / Express请求实体太大 - Heroku的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到无处不在,似乎没有找到解释,这是Heroku在我的日志中显示的:

  45:45 + 00:00 app [web.7]:错误:请求实体太大
45:45 + 00:00 app [web.7]:在Object.error(/ app / node_modules / express / node_modules / connect / lib / utils.js:44:13)
45:45 + 00:00 app [web.7]:在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]:在Object.logger [as handle](/ app / node_modules / express / node_modules / connect / lib /中间件/ logger.js:157:5)
45:45 + 00:00 app [web.7]:在下一个(/app/node_modules/express/node_modules/connect/lib/proto.js:190: 15)
45:45 + 00:00 app [web.7]:在Object.favicon [as handle](/app/node_modules/express/node_modules/connect/lib/middleware/favicon.js:78: 7)
45:45 + 00:00 app [web.7]:在下一个(/app/node_modules/express/node_modules/connect/lib/proto.js:190:15)
45:45 + 00:00 app [web.7]:在Object.expressInit [as handle] (/app/node_modules/express/lib/middleware.js:31:5)
45:45 + 00:00 app [web.7]:在下一个(/ app / node_modules / express / node_modules / connect / lib / proto.js:190:15)
45:45 + 00:00 app [web.7]:在Object.query [as handle](/ app / node_modules / express / node_modules / connect / lib /中间件/ query.js:44:5)
45:45 + 00:00 app [web.7]:POST / mls 413 1ms - 980

我已经包括最后一个日志记录,因为我不确定它是否建议HTTP URL发生这些错误,或者如果是下一个请求的URL,那么Heroku dyno正在处理(我们收到数百个请求一秒钟,所以跟踪有点疯狂)。



我的应用程序( ExpressJS )需要接收到大量的POST请求,这就是为什么我把

  app.use(express.limit('5mb'));在应用程序的顶部,

,以允许大的帖子请求(通常小于2MB)。我不知道上面的错误是否是由于接收到太大的请求或尝试向S3发送请求太大或者其他问题引起的。任何想法?



谢谢!

解决方案

v4 +你可以使用

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

但请确保此行高于

  app.use(bodyParser.json()); 

否则将无法正常工作


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!

解决方案

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

这篇关于NodeJS / Express请求实体太大 - Heroku的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆