Allow fields that have multiple values
This commit is contained in:
parent
82279ccacb
commit
cda8ff2e17
|
@ -26,6 +26,7 @@ Uploader.prototype.processUpload = function (req, res, cb) {
|
|||
var client = this.client;
|
||||
var form = new IncomingForm(this.options);
|
||||
var container = req.params.container;
|
||||
var fields = {}, files = {};
|
||||
form.handlePart = function (part) {
|
||||
var self = this;
|
||||
|
||||
|
@ -43,7 +44,14 @@ Uploader.prototype.processUpload = function (req, res, cb) {
|
|||
});
|
||||
|
||||
part.on('end', function () {
|
||||
self.emit('field', part.name, value);
|
||||
var values = fields[part.name];
|
||||
if(values === undefined) {
|
||||
values = [value];
|
||||
fields[part.name] = values;
|
||||
} else {
|
||||
values.push(value);
|
||||
}
|
||||
self.emit('field', part.name + '[' + (values.length -1) + ']', value);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
@ -70,13 +78,20 @@ Uploader.prototype.processUpload = function (req, res, cb) {
|
|||
part.on('end', function () {
|
||||
writer.end(function () {
|
||||
self._flushing--;
|
||||
self.emit('file', part.name + ':' + file.name, file);
|
||||
var values = files[part.name];
|
||||
if(values === undefined) {
|
||||
values = [file];
|
||||
files[part.name] = values;
|
||||
} else {
|
||||
values.push(file);
|
||||
}
|
||||
self.emit('file', part.name + '[' + (values.length -1) + ']', file);
|
||||
self._maybeEnd();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
form.parse(req, function (err, fields, files) {
|
||||
form.parse(req, function (err, _fields, _files) {
|
||||
cb && cb(err, {files: files, fields: fields});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue