admin管理员组

文章数量:1322683

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.

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

Here is the current configuration:

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?

More information

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 IningMessage.bound (/home/nodejs/server/node_modules/lodash/dist/lodash.js:729:21)
        at emitNone (events.js:111:20)
        at IningMessage.emit (events.js:208:7)
        at endReadableNT (_stream_readable.js:1056:12)
        at _binedTickCallback (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>'
}

Solution

The error was indeed due to wrong configuration on elasticsearch and not nodejs. Manage to fix this by following and setting http.max_content_length: 500mb in elasticsearch.yml.

@ryanlutgen also provided a link for more information about this error here.

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

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.

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

Here is the current configuration:

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?

More information

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 IningMessage.bound (/home/nodejs/server/node_modules/lodash/dist/lodash.js:729:21)
        at emitNone (events.js:111:20)
        at IningMessage.emit (events.js:208:7)
        at endReadableNT (_stream_readable.js:1056:12)
        at _binedTickCallback (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>'
}

Solution

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

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

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

Share Improve this question edited Dec 31, 2017 at 10:39 s4135 asked Dec 30, 2017 at 14:53 s4135s4135 751 gold badge1 silver badge5 bronze badges 14
  • Try removing this line app.use(bodyParser()) – Devang Naghera Commented Dec 30, 2017 at 14:55
  • 1 You should never send that much data. You should send your data in chunks to avoid timeouts, like when you upload a video through YouTube's API. See developers.google./youtube/v3/guides/… In our app, we upload in 50Mb chunks – Ruan Mendes Commented Dec 30, 2017 at 14:56
  • without that last line, the same error still occurs. I added that hoping that the error will be solved but it didn't sadly – s4135 Commented Dec 30, 2017 at 14:56
  • i would send it in chunks if i could. but due to limitations set, i can't do it unfortunately. The node can process it if its at 200k-300k~ but once it hits 400k, the error will occur. Or could nodejs split the json into chunks? if it could, it might work. – s4135 Commented Dec 30, 2017 at 15:00
  • 1 Am I reading wrong? or you just want to send 15360 MB data in one request? – gokcand Commented Dec 30, 2017 at 15:04
 |  Show 9 more ments

2 Answers 2

Reset to default 3

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

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

I'm not using bodyParser so I've fixed my issue with the following:

app.use(express.json({
  limit: '2MB',
}));

本文标签: javascriptNodeJS Express Request Entity Too LargeStack Overflow