apostrophe: PayloadTooLargeError: request entity too large when trying to POST to apostrophe-headless API

I am using apostrophe-headless, and my payloads are slightly big since I am storing images as base64 strings, so some of the requests fail with this:

PayloadTooLargeError: request entity too large
    at readStream (/Users/marjan/Projects/marketplace-backend/node_modules/raw-body/index.js:155:17)
    at getRawBody (/Users/marjan/Projects/marketplace-backend/node_modules/raw-body/index.js:108:12)
    at read (/Users/marjan/Projects/marketplace-backend/node_modules/body-parser/lib/read.js:77:3)
    at jsonParser (/Users/marjan/Projects/marketplace-backend/node_modules/body-parser/lib/types/json.js:134:5)
    at Layer.handle [as handle_request] (/Users/marjan/Projects/marketplace-backend/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/marjan/Projects/marketplace-backend/node_modules/express/lib/router/index.js:317:13)
    at /Users/marjan/Projects/marketplace-backend/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/marjan/Projects/marketplace-backend/node_modules/express/lib/router/index.js:335:12)
    at next (/Users/marjan/Projects/marketplace-backend/node_modules/express/lib/router/index.js:275:10)
    at urlencodedParser (/Users/marjan/Projects/marketplace-backend/node_modules/body-parser/lib/types/urlencoded.js:100:7)
    at Layer.handle [as handle_request] (/Users/marjan/Projects/marketplace-backend/node_modules/express/lib/router/layer.js:95:5)
    at trim_prefix (/Users/marjan/Projects/marketplace-backend/node_modules/express/lib/router/index.js:317:13)
    at /Users/marjan/Projects/marketplace-backend/node_modules/express/lib/router/index.js:284:7
    at Function.process_params (/Users/marjan/Projects/marketplace-backend/node_modules/express/lib/router/index.js:335:12)
    at next (/Users/marjan/Projects/marketplace-backend/node_modules/express/lib/router/index.js:275:10)
    at self.csrf (/Users/marjan/Projects/marketplace-backend/node_modules/apostrophe/lib/modules/apostrophe-express/index.js:447:16)

I tried setting apostrophe-express.bodyParser to {limit: '50mb', extended: true}, but that doesn’t seem to work.

Any ideas on how to increase the request size limit?

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 20 (3 by maintainers)

Most upvoted comments

This seems to have worked:

bodyParser = {
  json: {limit: '50mb', extended: true},
  urlencoded: {limit: '50mb', extended: true}
};

better use (you can change the limit of data as you wish - for example 10mb):

app.use(bodyParser.json({limit: ‘10mb’, extended: true})) app.use(bodyParser.urlencoded({limit: ‘10mb’, extended: true}))

i tried change limit on node_module body-parser from 100kb to 10000kb and it works

This work for me

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

app.use(bodyParser.urlencoded({
  limit: '50mb',
  parameterLimit: 100000,
  extended: true 
}));

if you using Nginx on your server you should config Nginx too

server {
    ...
   client_body_buffer_size    50M; 
   client_max_body_size       50M;
}

better use (you can change the limit of data as you wish - for example 10mb):

app.use(bodyParser.json({limit: ‘10mb’, extended: true})) app.use(bodyParser.urlencoded({limit: ‘10mb’, extended: true}))

workng for me thanks