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

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

问题描述

我尝试了此处列出的许多解决方案(增加内存限制,添加参数限制,将类型添加为 application / json)来解决此请求实体太大错误(它还会返回http代码413)。

I've tried many solutions listed here (increasing of memory limit, adding parameterlimit, adding type as 'application/json') to fix this 'Request Entity too large' error (it also returns http code 413). But none of them seem to make this error go away.

当前json的大小范围从200k到40万个实体。

The current size of the json can range from 200k up to 400k entities.

以下是当前配置:

app.use( bodyParser.json({limit: "15360mb", type:'application/json'}) );      
app.use(bodyParser.urlencoded({
  limit: "15360mb",
  extended: true,
  parameterLimit:5000000,
  type:'application/json'
})); 
app.use(bodyParser())

关于如何增加限额的任何想法?

Any ideas on how to increase the limit?

更多信息

如果有帮助,这是完整的错误消息:

This is the full error message if it helps:

    { Error: Request Entity Too Large
        at respond (/home/nodejs/server/node_modules/elasticsearch/src/lib/transport.js:307:15)
        at checkRespForFailure (/home/nodejs/server/node_modules/elasticsearch/src/lib/transport.js:266:7)
        at HttpConnector.<anonymous> (/home/nodejs/server/node_modules/elasticsearch/src/lib/connectors/http.js:159:7)
        at IncomingMessage.bound (/home/nodejs/server/node_modules/lodash/dist/lodash.js:729:21)
        at emitNone (events.js:111:20)
        at IncomingMessage.emit (events.js:208:7)
        at endReadableNT (_stream_readable.js:1056:12)
        at _combinedTickCallback (internal/process/next_tick.js:138:11)
        at process._tickCallback (internal/process/next_tick.js:180:9)
      status: 413,
      displayName: 'RequestEntityTooLarge',
      message: 'Request Entity Too Large',
      path: '/_bulk',
      query: {},
      body: '<large body here>'
}

解决方案

错误确实是由于对Elasticsearch而不是nodejs的错误配置。遵循> https://github.com/elastic/elasticsearch-js/ Issues / 241 并在 elasticsearch.yml 中设置 http.max_content_length:500mb

The error was indeed due to wrong configuration on elasticsearch and not nodejs. Manage to fix this by following https://github.com/elastic/elasticsearch-js/issues/241 and setting http.max_content_length: 500mb in elasticsearch.yml.

@ryanlutgen还在此处提供了有关此错误的更多信息的链接。
https://github.com/elastic/elasticsearch/issues/2902

@ryanlutgen also provided a link for more information about this error here. https://github.com/elastic/elasticsearch/issues/2902

此问题已解决。谢谢您的所有投入!

This issue has been fixed. Thanks for all the input!

推荐答案

如果您不能解决问题,bodyParser也会提供限制
您必须使用

If You doesn't solve your issue, bodyParser also has a limit. You must use

app.use(bodyParser({limit: '4MB'}))

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

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