diff --git a/samples/Node.js/app.js b/samples/Node.js/app.js index 8c7ee386..0e38c8f3 100644 --- a/samples/Node.js/app.js +++ b/samples/Node.js/app.js @@ -4,6 +4,7 @@ var express = require('express'); var multipart = require('connect-multiparty'); var multipartMiddleware = multipart(); var flow = require('./flow-node.js')('tmp'); +var fs = require('fs'); var app = express(); // Configure access control allow origin header stuff @@ -17,6 +18,13 @@ app.use(express.static(__dirname + '/../../src')); app.post('/upload', multipartMiddleware, function(req, res) { flow.post(req, function(status, filename, original_filename, identifier) { console.log('POST', status, original_filename, identifier); + if (status == 'done') { + // Assemble Chunks + var stream = fs.createWriteStream('uploads/' + identifier); + flow.write(identifier, stream); + // Clean chunks after the file is assembled + flow.clean(identifier); + } if (ACCESS_CONTROLL_ALLOW_ORIGIN) { res.header("Access-Control-Allow-Origin", "*"); } @@ -51,8 +59,8 @@ app.get('/upload', function(req, res) { }); }); -app.get('/download/:identifier', function(req, res) { - flow.write(req.params.identifier, res); +app.get('/download/:identifier/:name', function(req, res) { + res.download('uploads/' +req.params.identifier, req.params.name); }); app.listen(3000); diff --git a/samples/Node.js/uploads/.gitignore b/samples/Node.js/uploads/.gitignore new file mode 100644 index 00000000..209c543f --- /dev/null +++ b/samples/Node.js/uploads/.gitignore @@ -0,0 +1,3 @@ +* + +!.gitignore \ No newline at end of file