どうやら、ユニオンオプションでバッファリングをオフにする必要があり、ストリーミング:エンドポイントのオプションでtrue:
var fs = require('fs'),
path = require('path'),
union = require('../../lib'),
director = require('director'),
favicon = require('./middleware/favicon'),
// for uploading:
formidable = require('formidable'),
util = require('util');
var router = new director.http.Router();
var server = union.createServer({
buffer: false,
before: [
favicon(path.join(__dirname, 'favicon.png')),
function (req, res) {
var found = router.dispatch(req, res);
if (!found) {
res.emit('next');
}
}
]
});
router.get('/foo', function () {
this.res.writeHead(200, { 'Content-Type': 'text/html' });
this.res.end('<form action="/foo" enctype="multipart/form-data" method="post">'+
'<input type="text" name="title"><br>'+
'<input type="file" name="upload" multiple="multiple"><br>'+
'<input type="submit" value="Upload">'+
'</form>');
});
router.post('/foo', { stream: true }, function () {
var req = this.req,
res = this.res,
writeStream;
var form = new formidable.IncomingForm();
console.log('Receiving file upload');
form
.on('field', function(field, value) {
console.log(field, value);
})
.on('file', function(field, file) {
console.log(field, file);
})
.on('progress', function(rec, expected) {
console.log("progress: " + rec + " of " +expected);
})
.parse(req, function(err, fields, files) {
console.log('Parsed file upload' + err);
res.writeHead(200, { 'Content-Type': 'text/plain' });
if (err) {
res.end('error: Upload failed: ' + err);
}
else {
res.end('success: Uploaded file(s): ' + util.inspect({fields: fields, files: files}));
}
});
});
server.listen(9090);
console.log('union with director running on 9090');