Search code examples
node.jsmongodbexpresslimitbusboy

busboy fileSize limit event is not being called


I'm uploading a file using express into a MongoDb. All is working fine, but now I'm trying to set a size limit. Setting busboy configuration as busboy site declares:

 var busboy = new Busboy({ headers: req.headers,  limit: { files: 1, fileSize: 50000 }  });

then:

file.on('limit', function(data) {                                               
     console.log("LIMIT");
});

By the way, I can try to find a workaround by stopping everything when the data chucks add up to the limit size.

file.on('data', function(data) {                                          
   fileSize+=data.length;
    if (fileSize>50000){
        //limit reached 
   }                         
});

Solution

  • The limit config option is limits and not limit. Change that and it should work.