0

I have a node app running v0.10.33 with Restify module ^2.8.3

var app = restify.createServer();
app.use(restify.queryParser());
app.use(restify.bodyParser({
  maxBodySize: 1, //TODO: This limit is not working at the moment.
  uploadDir: './temp',
  keepExtensions: true
}));

app.post('/users/profile/picture', function(req, res, next) {
  res.end('Upload done!');
};

The upload of the file works but it does not respect the maxBodySize param. The rest of the params: keepExtensions, uploadDir, etc work well.

Why is the maxBodySize being ignored?

Mat Zero
  • 386
  • 3
  • 9
  • have you tried using it with other limits? does it work with any other than 1? – Laura Dec 16 '14 at 08:31
  • Yes, I've tried 0, 100000, "100", "1000000", "1". I've also tried using the "limit: 100" and limit: '10mb' combos. But under the covers I can see it is using Formidable so those last params won't work, I think they are for busyboy plugin. – Mat Zero Dec 16 '14 at 18:05

1 Answers1

0

Because your contentType is multipart/form-data or octet-stream
At lib/plugins/body_reader.js

if ((req.getContentLength() === 0 && !req.isChunked()) ||
        req.contentType() === 'multipart/form-data' ||
        req.contentType() === 'application/octet-stream') {
        next();
        return;
     }
    var bodyWriter = createBodyWriter(req);
    function done() {
        if (maxBodySize && bytesReceived > maxBodySize) {
            var msg = 'Request body size exceeds ' +
                maxBodySize;
            next(new RequestEntityTooLargeError(msg));
            return;
        }
Juan R
  • 193
  • 2
  • 8
  • RequestEntityTooLarge has been renamed to PayloadTooLargeError between Node 0.12 and 4. For any recent development use PayloadTooLargeError. – ivosh Jul 25 '19 at 03:18