Skip to content

Commit

Permalink
Merge pull request #20 from tomhigginsuom/master
Browse files Browse the repository at this point in the history
Support arrays of fields (similar to busboy 'autoFields' option)
  • Loading branch information
richardgirges authored Feb 17, 2017
2 parents d68e4a1 + cc07b11 commit 568f211
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ module.exports = function(options) {

req.busboy.on('field', function(fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) {
req.body = req.body || {};
req.body[fieldname] = val;
var prev = req.body[fieldname];
if (!prev) return req.body[fieldname] = val;
if (Array.isArray(prev)) return prev.push(val);
req.body[fieldname] = [prev, val];
});

req.busboy.on('file', function(fieldname, file, filename, encoding, mimetype) {
Expand Down

0 comments on commit 568f211

Please sign in to comment.