From 210618d7b30d147b6e9fbd4c7d58c1a687b52ad9 Mon Sep 17 00:00:00 2001 From: Raymond Feng Date: Thu, 27 Jun 2013 08:31:03 -0700 Subject: [PATCH] Handle fields/files --- lib/storage-handler.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib/storage-handler.js b/lib/storage-handler.js index 79da5ba..deeeaf9 100644 --- a/lib/storage-handler.js +++ b/lib/storage-handler.js @@ -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}); }); }