Handle fields/files
This commit is contained in:
parent
d6b89fe2ef
commit
210618d7b3
|
@ -17,8 +17,6 @@ Uploader.prototype.processUpload = function (req, res, cb) {
|
||||||
var client = this.client;
|
var client = this.client;
|
||||||
var form = new IncomingForm(this.options);
|
var form = new IncomingForm(this.options);
|
||||||
var container = req.params.container;
|
var container = req.params.container;
|
||||||
var fields = {};
|
|
||||||
var files = {};
|
|
||||||
form.handlePart = function (part) {
|
form.handlePart = function (part) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
@ -36,7 +34,6 @@ Uploader.prototype.processUpload = function (req, res, cb) {
|
||||||
});
|
});
|
||||||
|
|
||||||
part.on('end', function () {
|
part.on('end', function () {
|
||||||
fields[part.name] = value;
|
|
||||||
self.emit('field', part.name, value);
|
self.emit('field', part.name, value);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
|
@ -44,6 +41,14 @@ Uploader.prototype.processUpload = function (req, res, cb) {
|
||||||
|
|
||||||
this._flushing++;
|
this._flushing++;
|
||||||
|
|
||||||
|
var file = {
|
||||||
|
container: container,
|
||||||
|
name: part.filename,
|
||||||
|
type: part.mime
|
||||||
|
};
|
||||||
|
|
||||||
|
self.emit('fileBegin', part.name, file);
|
||||||
|
|
||||||
var writer = client.upload({container: container, remote: part.filename});
|
var writer = client.upload({container: container, remote: part.filename});
|
||||||
|
|
||||||
part.on('data', function (buffer) {
|
part.on('data', function (buffer) {
|
||||||
|
@ -56,14 +61,13 @@ Uploader.prototype.processUpload = function (req, res, cb) {
|
||||||
part.on('end', function () {
|
part.on('end', function () {
|
||||||
writer.end(function () {
|
writer.end(function () {
|
||||||
self._flushing--;
|
self._flushing--;
|
||||||
files[part.name] = part.filename;
|
self.emit('file', part.name, file);
|
||||||
self._maybeEnd();
|
self._maybeEnd();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
form.parse(req, function (err, result) {
|
form.parse(req, function (err, fields, files) {
|
||||||
console.log(result);
|
|
||||||
cb && cb(err, {files: files, fields: fields});
|
cb && cb(err, {files: files, fields: fields});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue