From 42b4a04af0d847cf93c9c15ad9ebcc96f35955b3 Mon Sep 17 00:00:00 2001 From: Paul Klemm Date: Thu, 22 Jan 2015 16:00:32 +0100 Subject: [PATCH 1/5] added upload folder for assembled files --- samples/Node.js/uploads/.gitignore | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 samples/Node.js/uploads/.gitignore 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 From 2ef56367992e839644941310f2e5220bc78982c0 Mon Sep 17 00:00:00 2001 From: Paul Klemm Date: Thu, 22 Jan 2015 16:01:09 +0100 Subject: [PATCH 2/5] file is now assembled after all chunks are uploaded. Fixes flowjs/flow.js#17 --- samples/Node.js/app.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/samples/Node.js/app.js b/samples/Node.js/app.js index 8c7ee386..3afb2dc2 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,9 @@ 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); + // Assemble Chunks + var stream = fs.createWriteStream('uploads/' + filename); + flow.write(identifier, stream); if (ACCESS_CONTROLL_ALLOW_ORIGIN) { res.header("Access-Control-Allow-Origin", "*"); } From 3e23096679f8e041024c3056088b5925f7afe115 Mon Sep 17 00:00:00 2001 From: Paul Klemm Date: Thu, 22 Jan 2015 17:35:39 +0100 Subject: [PATCH 3/5] only assemble files when status is 'done' --- samples/Node.js/app.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/samples/Node.js/app.js b/samples/Node.js/app.js index 3afb2dc2..8c704919 100644 --- a/samples/Node.js/app.js +++ b/samples/Node.js/app.js @@ -18,9 +18,11 @@ 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); - // Assemble Chunks - var stream = fs.createWriteStream('uploads/' + filename); - flow.write(identifier, stream); + if (status == 'done') { + // Assemble Chunks + var stream = fs.createWriteStream('uploads/' + filename); + flow.write(identifier, stream); + } if (ACCESS_CONTROLL_ALLOW_ORIGIN) { res.header("Access-Control-Allow-Origin", "*"); } From 5631eadbb7cbee0bfa07db270bb51ed1ceccd312 Mon Sep 17 00:00:00 2001 From: Paul Klemm Date: Sun, 1 Feb 2015 12:55:36 +0100 Subject: [PATCH 4/5] clean chunks after the file is assembled --- samples/Node.js/app.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/samples/Node.js/app.js b/samples/Node.js/app.js index 8c704919..951d2f93 100644 --- a/samples/Node.js/app.js +++ b/samples/Node.js/app.js @@ -22,6 +22,8 @@ app.post('/upload', multipartMiddleware, function(req, res) { // Assemble Chunks var stream = fs.createWriteStream('uploads/' + filename); 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", "*"); From f0aa6c0755800c95968aaf12b33772aad534cd84 Mon Sep 17 00:00:00 2001 From: Paul Klemm Date: Sun, 1 May 2016 17:55:30 +0200 Subject: [PATCH 5/5] Save assembled file using its identifier --- samples/Node.js/app.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/samples/Node.js/app.js b/samples/Node.js/app.js index 951d2f93..0e38c8f3 100644 --- a/samples/Node.js/app.js +++ b/samples/Node.js/app.js @@ -20,7 +20,7 @@ app.post('/upload', multipartMiddleware, function(req, res) { console.log('POST', status, original_filename, identifier); if (status == 'done') { // Assemble Chunks - var stream = fs.createWriteStream('uploads/' + filename); + var stream = fs.createWriteStream('uploads/' + identifier); flow.write(identifier, stream); // Clean chunks after the file is assembled flow.clean(identifier); @@ -59,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);