Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
marjan-georgiev opened this issue Mar 24, 2018 · 20 comments

Comments

@marjan-georgiev
Copy link

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?

@marjan-georgiev
Copy link
Author

This seems to have worked:

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

@boutell
Copy link
Member

boutell commented Mar 26, 2018

Interesting. Most of the time JSON encoding is used with apostrophe-headless, and we did bump up the limit for JSON to 16MB recently in the latest npm version of apostrophe. Glad you were able to find the correct configuration for your needs.

@moshepeled
Copy link

moshepeled commented Jul 22, 2018

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}))

@sanakdam
Copy link

sanakdam commented Aug 9, 2018

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

@gandalivs
Copy link

gandalivs commented Oct 17, 2018

if your data type object or object list, why you dont format your data as JSON.
when you send data :
var sendData = json.Stringify(yourObject);

when you get data
var getData = json.Parse(sendData);

@pepo205
Copy link

pepo205 commented Feb 12, 2019

You can avoid parse payload, in case you don't need it (file transfering for example), using param parseReqBody: false

@pronebird
Copy link

@pepo205 parseReqBody is not documented anywhere.

@boutell
Copy link
Member

boutell commented Apr 1, 2019

Yeah, I don't think parseReqBody is a thing.

Setting the limit on body-parser is the way to go.

@Gricardov
Copy link

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

This was the answer I was looking for! Thanks. I had a base64 encoded json string and couldn't change the limit in any other way

@courageDeveloper
Copy link

@marjan-georgiev thanks a lot. I used app.use(bodyParser.urlencoded({limit: '50mb', extended: true }));
app.use(bodyParser.json({limit: '50mb', extended: true})); Which is basically the same thing.

@ravi-kumar-beniwal
Copy link

Better use you can specify the limit of your file size as it shown in given line

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

You can also change the default setting in node-modules body-parser then in the lib folder, there are JSON and text file. Then change limit here. Actually, this condition pass if you don't pass the limit parameter in the given line
app.use(bodyParser.json({limit: '10mb', extended: true})).

@maksof-Rehan
Copy link

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

@sudhir600
Copy link

Worked for me.. Thanks

@Abhinash16
Copy link

When you are trying to send data from postman, remove the header and than try to upload,
and remember to use the same key while uploading the image that you have used during defining multer single method,
eg: single.('Image', 10);
from postman send "Image":
and uncheck the header content : see pic for ref
Screenshot (4)

@Redsandro
Copy link

But what are the default limits?

@ghost
Copy link

ghost commented Dec 12, 2019

Thank you for the solution works for me!
app.use(bodyParser.json({limit: '10mb', extended: true}))
app.use(bodyParser.urlencoded({limit: '10mb', extended: true}))

If it still not working check the location where you set it. For me it works after I set it to one of the first "app.use" elements.

@SailorDev
Copy link

Thank you for the solution works for me!
app.use(bodyParser.json({limit: '10mb', extended: true})) app.use(bodyParser.urlencoded({limit: '10mb', extended: true}))

If it still not working check the location where you set it. For me it works after I set it to one of the first "app.use" elements.

it still not working for me

@m-nur
Copy link

m-nur commented Jan 4, 2020

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;
}

@ganeshBUnbound
Copy link

This work for me

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

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

Thanks man. It worked for me

@boutell
Copy link
Member

boutell commented Mar 11, 2020

Hi folks, since @marjan-georgiev gave the right answer for Apostrophe long ago (see above), I am locking this thread. For general questions about the body-parser module unrelated to apostrophe please see the body-parser module documentation which does cover all this.

@apostrophecms apostrophecms locked as resolved and limited conversation to collaborators Mar 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests