Skip to content

Commit

Permalink
Merge pull request #22 from targos/improve-perf
Browse files Browse the repository at this point in the history
improve performance for large files
  • Loading branch information
richardgirges authored Mar 9, 2017
2 parents ac309ee + e23f337 commit 90267a3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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.
Expand Down

0 comments on commit 90267a3

Please sign in to comment.