A127 file upload fails with a http 413 for just 318kb of file

Not applicable

I have this file upload api (multipart/form-data) and I run into a http 413 when I upload a 318 kb json file.

{
  "expected": 313066,
  "length": 313066,
  "limit": 102400,
  "status": 413,
  "statusCode": 413,
  "message": "request entity too large",
  "type": "entity.too.large"
}

Swagger-node uses multer internally. And multer doesn't really impose any restrictions.https://github.com/expressjs/multer#limits - it's infinity by default.

and neither do you, in swagger tools, https://github.com/apigee-127/swagger-tools/blob/master/middleware/swagger-metadata.js#L41, impose any limits.

I run express 4, so body parser is ruled out.

I am running on localhost, no nginx or any other proxy in between.

0 10 10.4K
10 REPLIES 10

Not applicable

@Jeremy Whitlock @Scott Ganyo: any answers here? This is hindering us from upgrading to express 4

Not applicable

at the moment we fallback on express 3 as suggested here https://github.com/swagger-api/swagger-node/issues/338

Not applicable

I don't have anything offhand. What version of swagger-express-mw are you running?

Whatever comes packed with a127 project create. I don't use standalone swagger-express-mw.

Ah, ok. So you're using apigee-127, not swagger-node, correct?

absolutely.

Absolutely. We use a127.

Not applicable

One thing worth a try is to register your own multipart parser middleware (be it multr or something else) before the "app.use(a127.middleware())" call in your app.js. As long as your middleware sets the req.files property, the included middleware in swagger-tools shouldn't run and so you should be able to have full control of the parser and it's properties.

Not applicable

We are suffering from a similar problem when using swagger-express-mw - we get this error when trying to upload JSON files of greater than 100Kb. It looks like it's caused by the use of body-parser within swagger-tools. According to the body-parser README.md the default limit is 100Kb. This can be overridden by passing in options, but the options are hardcoded in swagger-tools/middleware/swagger-metadata.js to be:

var bodyParserOptions = { extended: false};

There doesn't currently appear to be a way to specify anything different. This is likely to be a major problem for us, unless we can find a way to get around it.

EDIT:

You can work around this problem by including your own body parser middleware upstream of the swagger-express-mw.

For example.

var bodyParser = require( 'body-parser' );

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

Will allow through JSON bodies of up to 50MB. You could do something similar with bodyParser.urlEncoded() or bodyParser.text() if you needed to.

I was able to resolve this error by not declaring a bodyParser. Setting a bodyParser enforces the default limit by express. I commented out the following

//app.use(express.bodyParser());