diff --git a/lib/index.js b/lib/index.js index e93291d..c34d443 100644 --- a/lib/index.js +++ b/lib/index.js @@ -67,11 +67,11 @@ function processMultipart(options, req, res, next) { // Build req.files fields busboy.on('file', function(fieldname, file, filename, encoding, mime) { - let buf = new Buffer(0); + const buffers = []; let safeFileNameRegex = /[^\w-]/g; file.on('data', function(data) { - buf = Buffer.concat([buf, data]); + buffers.push(data); if (options.debug) return console.log('Uploading %s -> %s', fieldname, filename); @@ -81,6 +81,7 @@ function processMultipart(options, req, res, next) { if (!req.files) req.files = {}; + const buf = Buffer.concat(buffers); // see: https://github.com/richardgirges/express-fileupload/issues/14 // firefox uploads empty file in case of cache miss when f5ing page. // resulting in unexpected behavior. if there is no file data, the file is invalid.