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

Error: Request Entity Too Large #710

Closed
laddi opened this issue Jul 11, 2014 · 25 comments
Closed

Error: Request Entity Too Large #710

laddi opened this issue Jul 11, 2014 · 25 comments

Comments

@laddi
Copy link

laddi commented Jul 11, 2014

We are trying to do some json parsing with a large file in a server route and run into this problem: "Error: Request Entity Too Large"

Instead of having to manually edit the package code it would be nice to have some kind of way to set the bodyParser limit in the configuration.

(same issue as here: http://stackoverflow.com/questions/23899209/setting-request-limit-in-a-meteor-js-app)

All help greatly appreciated.

@cmather
Copy link
Contributor

cmather commented Jul 13, 2014

Ah yes this should be much improved. I think the body parser is actually being used in Meteor core too. In the next major version of IR you can add connect middleware directly to the router and I won't be adding any middleware by default. So that might fix this issue. But if Meteor is already including bodyParser middleware upstream, then I guess you'd have to configure that too. As a short-term hack, can you configure the bodyParser middleware after it's been initialized? And just get to it through the connectHandlers array? I'll try to see if that's possible.

@cmather
Copy link
Contributor

cmather commented Jul 13, 2014

Meh looks hard to set the options after the fact. I'm not sure why we force using this middleware anyway. I would take a PR to devel to remove it. That way you can set it up yourself using WebApp.connectHandlers.use(...).

@cmather
Copy link
Contributor

cmather commented Jul 26, 2014

This is fixed in the refactor branch where you can add your own middleware. Due to be released sometime around the Meteor 0.9 release.

@gerwinbrunner
Copy link

This is still in the refactor branch, right?
When do you plan to put release those changes?

@gerwinbrunner
Copy link

Any timeframe on this?

@gerwinbrunner
Copy link

@cmather This is still now working right?

@gerwinbrunner
Copy link

Any updates on this?

@tmeasday
Copy link
Contributor

@gerwinbrunner yes I think you can add your own middleware with a line line

Router.use(Router.bodyParser.urlencoded());

@gerwinbrunner
Copy link

@tmeasday It seems that this feature is only available in a version that is not yet available thru the regular packaging system. Can you point me to some resource on how I can easily add a package directly from a github url? Is there an easy way?

I did the following command:

meteor add iron:router

So is there something similar to add a package with an github url?
Somehing like this:

meteor add iron:router https://github.com/EventedMind/iron-router/

Or what is the easiest way for me to use this feature you mentioned above?

Thanks,
Gerwin

P.S.: Sorry if this is a stupid question, but I was not able to find any good solution yet.

@tmeasday
Copy link
Contributor

Hey @gerwinbrunner - sorry. You can install the latest pre-release of IR 1.0 with meteor add iron:router@1.0.0-pre4

@gerwinbrunner
Copy link

@tmeasday Thanks. I'll give it a try.

@gerwinbrunner
Copy link

@tmeasday: Just tried it with version 1.0.1 and I get the following error:

W20141109-21:02:53.792(1)? (STDERR) /Users/ap/.meteor/packages/meteor-tool/.1.0.35.k5cfzw++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:173
W20141109-21:02:53.792(1)? (STDERR)                         throw(ex);
W20141109-21:02:53.792(1)? (STDERR)                               ^
W20141109-21:02:53.795(1)? (STDERR) TypeError: Cannot call method 'urlencoded' of undefined
W20141109-21:02:53.796(1)? (STDERR)     at server/router/api-routes.coffee:3:29
W20141109-21:02:53.796(1)? (STDERR)     at /Users/ap/Documents/workspaces/VilangoWork/le3_meteor_app_2/meteor/.meteor/local/build/programs/server/app/server/router/api-routes.coffee.js:51:3
W20141109-21:02:53.796(1)? (STDERR)     at /Users/ap/Documents/workspaces/VilangoWork/le3_meteor_app_2/meteor/.meteor/local/build/programs/server/boot.js:168:10
W20141109-21:02:53.796(1)? (STDERR)     at Array.forEach (native)
W20141109-21:02:53.796(1)? (STDERR)     at Function._.each._.forEach (/Users/ap/.meteor/packages/meteor-tool/.1.0.35.k5cfzw++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
W20141109-21:02:53.796(1)? (STDERR)     at /Users/ap/Documents/workspaces/VilangoWork/le3_meteor_app_2/meteor/.meteor/local/build/programs/server/boot.js:82:5

A call to Router.bodyParser gives me undefined

Do I need to do something else?

@gerwinbrunner
Copy link

@tmeasday

I also tried this:
Router.use( Iron.Router.bodyParser.urlencoded(), {where: 'server'} );

And it gave me this error:

W20141109-21:19:10.215(1)? (STDERR) Sun, 09 Nov 2014 20:19:10 GMT body-parser deprecated undefined extended: provide extended option at app/server/router/api-routes.coffee.js:4:35
W20141109-21:19:10.218(1)? (STDERR) 
W20141109-21:19:10.218(1)? (STDERR) /Users/ap/.meteor/packages/meteor-tool/.1.0.35.k5cfzw++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/fibers/future.js:173
W20141109-21:19:10.219(1)? (STDERR)                         throw(ex);
W20141109-21:19:10.219(1)? (STDERR)                               ^
W20141109-21:19:10.223(1)? (STDERR) TypeError: Object function router(req, res, next) {                                                          // 13
W20141109-21:19:10.223(1)? (STDERR)     //XXX this assumes no other routers on the parent stack which we should probably fix      // 14
W20141109-21:19:10.223(1)? (STDERR)     router.dispatch(req.url, {                                                                // 15
W20141109-21:19:10.223(1)? (STDERR)       request: req,                                                                           // 16
W20141109-21:19:10.223(1)? (STDERR)       response: res                                                                           // 17
W20141109-21:19:10.223(1)? (STDERR)     }, next);                                                                                 // 18
W20141109-21:19:10.224(1)? (STDERR)   } has no method 'use'
W20141109-21:19:10.224(1)? (STDERR)     at server/router/api-routes.coffee:3:7
W20141109-21:19:10.224(1)? (STDERR)     at /Users/ap/Documents/workspaces/VilangoWork/le3_meteor_app_2/meteor/.meteor/local/build/programs/server/app/server/router/api-routes.coffee.js:47:3
W20141109-21:19:10.224(1)? (STDERR)     at /Users/ap/Documents/workspaces/VilangoWork/le3_meteor_app_2/meteor/.meteor/local/build/programs/server/boot.js:168:10
W20141109-21:19:10.224(1)? (STDERR)     at Array.forEach (native)
W20141109-21:19:10.224(1)? (STDERR)     at Function._.each._.forEach (/Users/ap/.meteor/packages/meteor-tool/.1.0.35.k5cfzw++os.osx.x86_64+web.browser+web.cordova/meteor-tool-os.osx.x86_64/dev_bundle/lib/node_modules/underscore/underscore.js:79:11)
W20141109-21:19:10.224(1)? (STDERR)     at /Users/ap/Documents/workspaces/VilangoWork/le3_meteor_app_2/meteor/.meteor/local/build/programs/server/boot.js:82:5

@tmeasday
Copy link
Contributor

tmeasday commented Nov 9, 2014

Hi @gerwinbrunner

try

Router.onBeforeAction( Iron.Router.bodyParser.urlencoded(), {where: 'server'} );

@gerwinbrunner
Copy link

@tmeasday
Thanks for your quick reply. I was able to set the bodyParser now.
I still get the error :(

W20141110-00:39:25.207(1)? (STDERR) Error: request entity too large
W20141110-00:39:25.207(1)? (STDERR)     at makeError (/Users/ap/.meteor/packages/iron:router/.1.0.1.1uflvuf++os+web.browser+web.cordova/npm/node_modules/body-parser/node_modules/raw-body/index.js:184:15)
W20141110-00:39:25.207(1)? (STDERR)     at module.exports (/Users/ap/.meteor/packages/iron:router/.1.0.1.1uflvuf++os+web.browser+web.cordova/npm/node_modules/body-parser/node_modules/raw-body/index.js:40:15)
W20141110-00:39:25.207(1)? (STDERR)     at read (/Users/ap/.meteor/packages/iron:router/.1.0.1.1uflvuf++os+web.browser+web.cordova/npm/node_modules/body-parser/lib/read.js:62:3)
W20141110-00:39:25.207(1)? (STDERR)     at jsonParser (/Users/ap/.meteor/packages/iron:router/.1.0.1.1uflvuf++os+web.browser+web.cordova/npm/node_modules/body-parser/lib/types/json.js:87:5)
W20141110-00:39:25.207(1)? (STDERR)     at packages/iron:router/lib/router.js:264
W20141110-00:39:25.207(1)? (STDERR)     at _.extend.withValue (packages/meteor/dynamics_nodejs.js:56)
W20141110-00:39:25.208(1)? (STDERR)     at hookWithOptions (packages/iron:router/lib/router.js:263)
W20141110-00:39:25.208(1)? (STDERR)     at boundNext (packages/iron:middleware-stack/lib/middleware_stack.js:245)
W20141110-00:39:25.208(1)? (STDERR)     at runWithEnvironment (packages/meteor/dynamics_nodejs.js:108)
W20141110-00:39:25.208(1)? (STDERR)     at packages/meteor/dynamics_nodejs.js:121

Any ideas?

@tmeasday
Copy link
Contributor

tmeasday commented Nov 9, 2014

I think maybe it's a different body parser you need @gerwinbrunner ? I don't really know too much about this but by the sounds of it "urlencoded" probably doesn't deal with the body of the request?

@gerwinbrunner
Copy link

I got it working by forking iron:router and changing the file global_router.js to this:

Router = new Iron.Router;
if (Meteor.isServer) {
  Router.onBeforeAction(Iron.Router.bodyParser.json({limit: "10mb"}));
}

Just adding the line in my own code did not fix the error, so I had to fork and change the original.
But now it works. :)

@landland
Copy link

I'm running into this issue as well. Any chance we can up the limit in iron router?

@travisdahl
Copy link

+1. Trying to upload 3 images as base64 (i save to s3 on server) but limit wont allow

Clarification: I have the upload and everything working with small files, just having problems with the limit.

@cmather
Copy link
Contributor

cmather commented Feb 8, 2015

@gerwinbrunner has the right idea. But you can put this in Router.configureBodyParsers on the server. Look in lib/router_server.js for how it's done in source. Here's an example:

Router.configureBodyParsers = function () {
  Router.onBeforeAction(Iron.Router.bodyParser.json({limit: '10mb'});
};

For uploading files, @DirkStevens can you show an example of how to do it? We worked on an example together.

I haven't had time to properly integrate multipart uploading. Under the hood Iron Router just uses body parser for parsing http bodies. And at some point they decided not to support multipart uploads (I didn't realize this until last weekend). So we have to plug in a third party multipart uploading Connect middleware package, or you can do it yourself. There are a few npm packages for this (http://www.senchalabs.org/connect/multipart.html).

@DirkStevens
Copy link

Hey all - at #1190 you'll find info and a link to an experimental "multipart" package that @cmather and I worked on.

@travisdahl
Copy link

@cmather , just as @gerwinbrunner mentioned...

Just adding the line in my own code did not fix the error, so I had to fork and change the original.
But now it works. :)

adding this to my own server side code doesn't seem to make a difference. I still get the limit error. Any ideas why defining it in our own code wouldn't work?

OK, I figured it out...My orginal code that did NOT work was...

Router.configureBodyParsers = function() {
  Router.onBeforeAction(Iron.Router.bodyParser.json({
    limit: '500mb'
  }));
  Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({
    extended: true
  }));
};

I needed to just add the limit to the urlencoded like so:

Router.configureBodyParsers = function() {
  Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({
    extended: true,
    limit: '500mb'
  }));
};

THIS WORKS!

@kkm
Copy link

kkm commented Feb 24, 2015

@travisdahl
Can you tell me which version did you use for iron router?
I did try with 1.0.7.1 but doesnt work for me.

@kkm
Copy link

kkm commented Feb 24, 2015

AH I found:
Router = new Iron.Router;
Router.configureBodyParsers = function() {
Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({
extended : true,
limit : '500mb'
}));
};

I didnt know that it needs class of Iron.Router..that is fix now..thanks

@jackphilippi
Copy link

For people who still encounter this issue after adding the above snippet from @kkm (minus the not-needed Router = new Iron.Router; line), your problem may very well be the placement of the said snippet.

Move your Router.configureBodyParsers = function() ... snippet to be immediately before your route definitions. I had placed the snippet in a Meteor.startup() block in the server/main.js file and this did not work. Moving the snippet to lib/routes/main.js (immediately before my routes) solved this issue!

I believe this is because the Router object gets initialised after the code in server/main.js, meaning it overwrites the extended function. Hopefully this saves someone the months of trouble it caused me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants