Skip to content

Commit

Permalink
Issue/231: Updating NodeJS sample to make it work properly.
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkgr8 committed Jul 23, 2017
1 parent 172e3d1 commit 346e264
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
22 changes: 20 additions & 2 deletions samples/Node.js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -20,7 +21,22 @@ app.post('/upload', multipartMiddleware, function(req, res) {
if (ACCESS_CONTROLL_ALLOW_ORIGIN) {
res.header("Access-Control-Allow-Origin", "*");
}
res.status(status).send();

if(status==='done'){

var s = fs.createWriteStream('./uploads/' + filename);
s.on('finish', function() {

res.status(200).send();

});

flow.write(identifier, s, {end: true});
} else {
res.status(/^(partly_done|done)$/.test(status) ? 200 : 500).send();
}


});
});

Expand Down Expand Up @@ -55,4 +71,6 @@ app.get('/download/:identifier', function(req, res) {
flow.write(req.params.identifier, res);
});

app.listen(3000);
app.listen(3000, function(){
console.log('Server Started...');
});
4 changes: 2 additions & 2 deletions samples/Node.js/flow-node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
var fs = require('fs'),
path = require('path'),
util = require('util'),
mv = require('mv'),
Stream = require('stream').Stream;

module.exports = flow = function(temporaryFolder) {
Expand Down Expand Up @@ -107,9 +108,8 @@ module.exports = flow = function(temporaryFolder) {
var validation = validateRequest(chunkNumber, chunkSize, totalSize, identifier, filename, files[$.fileParameterName].size);
if (validation == 'valid') {
var chunkFilename = getChunkFilename(chunkNumber, identifier);

// Save the chunk (TODO: OVERWRITE)
fs.rename(files[$.fileParameterName].path, chunkFilename, function() {
mv(files[$.fileParameterName].path, chunkFilename, function() {

// Do we have all the chunks?
var currentTestChunk = 1;
Expand Down
3 changes: 2 additions & 1 deletion samples/Node.js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"dependencies": {
"connect-multiparty": "^1.0.4",
"express": "^4.3.1",
"connect-multiparty": "^1.0.4"
"mv": "^2.1.1"
}
}

0 comments on commit 346e264

Please sign in to comment.