Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve performance for large files #22

Merged
merged 1 commit into from
Mar 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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