Handle fields/files

This commit is contained in:
Raymond Feng 2013-06-27 08:31:03 -07:00
parent d6b89fe2ef
commit 210618d7b3
1 changed files with 10 additions and 6 deletions

View File

@ -17,8 +17,6 @@ Uploader.prototype.processUpload = function (req, res, cb) {
var client = this.client;
var form = new IncomingForm(this.options);
var container = req.params.container;
var fields = {};
var files = {};
form.handlePart = function (part) {
var self = this;
@ -36,7 +34,6 @@ Uploader.prototype.processUpload = function (req, res, cb) {
});
part.on('end', function () {
fields[part.name] = value;
self.emit('field', part.name, value);
});
return;
@ -44,6 +41,14 @@ Uploader.prototype.processUpload = function (req, res, cb) {
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});
part.on('data', function (buffer) {
@ -56,14 +61,13 @@ Uploader.prototype.processUpload = function (req, res, cb) {
part.on('end', function () {
writer.end(function () {
self._flushing--;
files[part.name] = part.filename;
self.emit('file', part.name, file);
self._maybeEnd();
});
});
};
form.parse(req, function (err, result) {
console.log(result);
form.parse(req, function (err, fields, files) {
cb && cb(err, {files: files, fields: fields});
});
}