Skip to content

Commit ec6270d

Browse files
committed
Fix input fields with multiple enabled:
- req.files[fieldname] is an Object when no multiple files are sent in the same field. - req.files[fieldname] is an Array of Objects when multiple files are sent for fieldname.
1 parent 994e1cb commit ec6270d

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/index.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ module.exports = function(options) {
5050
console.log('filename yo', filename);
5151
}
5252

53-
return req.files[fieldname] = {
53+
var newFile = {
5454
name: filename,
5555
data: buf,
5656
encoding: encoding,
@@ -67,6 +67,15 @@ module.exports = function(options) {
6767
});
6868
}
6969
};
70+
71+
if (!req.files.hasOwnProperty(fieldname)) {
72+
req.files[fieldname] = newFile;
73+
} else {
74+
if (req.files[fieldname] instanceof Array)
75+
req.files[fieldname].push(newFile);
76+
else
77+
req.files[fieldname] = [req.files[fieldname], newFile];
78+
}
7079
});
7180
});
7281

0 commit comments

Comments
 (0)