I'm going to upload a file using nodejs with express.
I see that bodyParser gets the job done...
app.use(express.bodyParser({"limit": '2mb'}));
But if I want to limit the size of the request I found that it doesn't cancel the upload somehow. The client keeps sending data.
So I wrote this middleware:
app.use(function (err, req, res, next) {
if(err.status == 413){
req.destroy();
return res.json({
"status": 413,
"message": err
},413);
}else
next(err);
});
It works, cancels the upload but the client doesn't get (or ignore) the response!
I think this could be a behavior of the http protocol, so any help is appreciated.