Skip to content

Commit

Permalink
Fix input fields with multiple enabled:
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
flplv committed Feb 7, 2017
1 parent 994e1cb commit ec6270d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = function(options) {
console.log('filename yo', filename);
}

return req.files[fieldname] = {
var newFile = {
name: filename,
data: buf,
encoding: encoding,
Expand All @@ -67,6 +67,15 @@ module.exports = function(options) {
});
}
};

if (!req.files.hasOwnProperty(fieldname)) {
req.files[fieldname] = newFile;
} else {
if (req.files[fieldname] instanceof Array)
req.files[fieldname].push(newFile);
else
req.files[fieldname] = [req.files[fieldname], newFile];
}
});
});

Expand Down

0 comments on commit ec6270d

Please sign in to comment.