Skip to content

Commit

Permalink
Added yarn. Added latest version of busboy; fixes #6.
Browse files Browse the repository at this point in the history
  • Loading branch information
richardgirges committed Feb 17, 2017
1 parent df3df26 commit 3d72084
Show file tree
Hide file tree
Showing 4 changed files with 388 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,15 @@ module.exports = function(options) {

req.busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
req.body = req.body || {};

var prev = req.body[fieldname];
if (!prev) return req.body[fieldname] = val;
if (Array.isArray(prev)) return prev.push(val);

if (!prev)
return req.body[fieldname] = val;

if (Array.isArray(prev))
return prev.push(val);

req.body[fieldname] = [prev, val];
});

Expand All @@ -29,9 +35,8 @@ module.exports = function(options) {
file.on('data', function(data) {
buf = Buffer.concat([buf, data]);

if (options.debug) {
if (options.debug)
return console.log('Uploading %s -> %s', fieldname, filename);
}
});

file.on('end', function() {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"description": "Simple express file upload middleware that wraps around connect-busboy",
"main": "./lib/index",
"dependencies": {
"busboy": "^0.2.14",
"connect-busboy": "0.0.2",
"fs-extra": "^0.22.1",
"streamifier": "^0.1.1"
Expand Down
2 changes: 2 additions & 0 deletions test/upload.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ app.post('/upload', function(req, res) {
return;
}

console.log('req.files >>>', req.files);

sampleFile = req.files.sampleFile;

uploadPath = __dirname + '/uploadedfiles/' + sampleFile.name;
Expand Down
Loading

0 comments on commit 3d72084

Please sign in to comment.