Permalink
Browse files

Added support for multiple files with the same field name

  • Loading branch information...
tj committed Oct 25, 2011
1 parent b3b83bf commit 6db7b91acb82d5eaa1552e87226d76a1c99450a4
Showing with 12 additions and 1 deletion.
  1. +12 −1 lib/multipart.js
View
@@ -395,6 +395,7 @@ Parser.middleware = function(options) {
Parser.handle = function(req, res, next, options) {
var parser = new Parser(req.headers['content-type'], options)
, diskLimit = options.diskLimit
+ , multiple = options.multiple
, limit = options.limit
, parts = {};
@@ -404,7 +405,17 @@ Parser.handle = function(req, res, next, options) {
});
parser.on('part', function(field, part) {
- parts[field] = part;
+ if (multiple) {
+ if (Array.isArray(parts[field])) {
+ parts[field].push(part);
+ } else if (parts[field]) {
+ parts[field] = [parts[field], part];
+ } else {
+ parts[field] = part;
+ }
+ } else {
+ parts[field] = part;
+ }
});
if (limit || diskLimit) {

0 comments on commit 6db7b91

Please sign in to comment.