Skip to content

Commit 3d72084

Browse files
committed
Added yarn. Added latest version of busboy; fixes #6.
1 parent df3df26 commit 3d72084

File tree

4 files changed

+388
-4
lines changed

4 files changed

+388
-4
lines changed

lib/index.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@ module.exports = function(options) {
1616

1717
req.busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
1818
req.body = req.body || {};
19+
1920
var prev = req.body[fieldname];
20-
if (!prev) return req.body[fieldname] = val;
21-
if (Array.isArray(prev)) return prev.push(val);
21+
22+
if (!prev)
23+
return req.body[fieldname] = val;
24+
25+
if (Array.isArray(prev))
26+
return prev.push(val);
27+
2228
req.body[fieldname] = [prev, val];
2329
});
2430

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

32-
if (options.debug) {
38+
if (options.debug)
3339
return console.log('Uploading %s -> %s', fieldname, filename);
34-
}
3540
});
3641

3742
file.on('end', function() {

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"description": "Simple express file upload middleware that wraps around connect-busboy",
66
"main": "./lib/index",
77
"dependencies": {
8+
"busboy": "^0.2.14",
89
"connect-busboy": "0.0.2",
910
"fs-extra": "^0.22.1",
1011
"streamifier": "^0.1.1"

test/upload.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ app.post('/upload', function(req, res) {
1919
return;
2020
}
2121

22+
console.log('req.files >>>', req.files);
23+
2224
sampleFile = req.files.sampleFile;
2325

2426
uploadPath = __dirname + '/uploadedfiles/' + sampleFile.name;

0 commit comments

Comments
 (0)