From 10263ab74174765d7b0ac9466900f79dd141a889 Mon Sep 17 00:00:00 2001 From: Mateusz Mrowiec Date: Fri, 1 Dec 2017 11:10:09 +0100 Subject: [PATCH] Handle 'limit' event when file is over fileSize --- lib/index.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/index.js b/lib/index.js index 24978ff..712ff78 100644 --- a/lib/index.js +++ b/lib/index.js @@ -73,6 +73,11 @@ function processMultipart(options, req, res, next) { const buffers = []; let safeFileNameRegex = /[^\w-]/g; + file.on('limit', () => { + res.writeHead(413, {'Connection': 'close'}); + res.end('File size limit has been reached'); + }); + file.on('data', function(data) { buffers.push(data);