From ab664eebc1afc9eee7e5d450e5e8c59edebc8191 Mon Sep 17 00:00:00 2001 From: Saurabh Gupta Date: Wed, 27 Sep 2017 15:18:35 +0530 Subject: [PATCH 1/3] update readme - initial more to be done --- readme.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/readme.md b/readme.md index 36638d3..34c05a4 100644 --- a/readme.md +++ b/readme.md @@ -1,3 +1,6 @@ +This fork is created to provide a better and correct example of fine-uploader server side nodejs example + + # Server-Side Examples for the Widen Fine Uploader Javascript Library # [![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE) From 38450fc6687556748aa568134482c7b7bf9660e2 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Sat, 30 Sep 2017 08:34:47 +0530 Subject: [PATCH 2/3] concurrent chunking async mode error-solution --- nodejs/nodejs.js | 57 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/nodejs/nodejs.js b/nodejs/nodejs.js index d1f58c4..9b5f1bf 100644 --- a/nodejs/nodejs.js +++ b/nodejs/nodejs.js @@ -39,9 +39,49 @@ app.listen(port); app.use(express.static(publicDir)); app.use("/node_modules", express.static(nodeModulesDir)); app.post("/uploads", onUpload); +app.post("/uploads/chunksdone", onChunksDone()); app.delete("/uploads/:uuid", onDeleteFile); +/* + In case of concurrent chunking, first all chunks are stored into a folder, + then a write operation is performed and finally I success request is sent + back. In async mode, this write operation and sending request to server is + not in sync. Therefore, many a times, you will havea request sent to the + server with an incomplete file (chunks not properly combined). + + FineUploader after sending all the chunks and getting a stored success request, + can send a post request to another route "/uploads/chunksdone" to know whether + the process is complete. This feature can be used to solve the problem explained + in the above paragraph. This is a personal fork just to cater this issue. + + */ + +function onChunksDone(req, res) { + /* + Payload for chunking success POST. + req.body = { + qquuid: the UUID of the underlying file. + qqfilename: the name of the underlying file. + qqtotalfilesize: the size, in bytes, of the underlying file. + qqtotalparts: the total number of parts that make up the underlying file. + } + */ + var file = req.body; + var uuid = req.body.qquuid; + + // call the combineChunks here to resolve the mentioned issue. + combineChunks(file, uuid, function() { + responseData.success = true; + res.send(responseData); + }, + function() { + responseData.error = "Problem conbining the chunks!"; + res.send(responseData); + }); + +} + function onUpload(req, res) { var form = new multiparty.Form(); @@ -101,14 +141,15 @@ function onChunkedUpload(fields, file, res) { res.send(responseData); } else { - combineChunks(file, uuid, function() { - responseData.success = true; - res.send(responseData); - }, - function() { - responseData.error = "Problem conbining the chunks!"; - res.send(responseData); - }); + + /* + Just send a chunks stored success request here. This will + trigger fine uploader to send a POST request to + "/uploads/chunksdone" route. + */ + responseData.success = true; + res.send(responseData); + } }, function(reset) { From a8fd976113ce5e3be7cb319e37ae7f29ea87549c Mon Sep 17 00:00:00 2001 From: Saurabh Date: Sat, 30 Sep 2017 08:39:26 +0530 Subject: [PATCH 3/3] final commit --- nodejs/nodejs.js | 1 + readme.md | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/nodejs/nodejs.js b/nodejs/nodejs.js index 9b5f1bf..99a17dd 100644 --- a/nodejs/nodejs.js +++ b/nodejs/nodejs.js @@ -44,6 +44,7 @@ app.delete("/uploads/:uuid", onDeleteFile); /* +Issue: In case of concurrent chunking, first all chunks are stored into a folder, then a write operation is performed and finally I success request is sent back. In async mode, this write operation and sending request to server is diff --git a/readme.md b/readme.md index 34c05a4..36638d3 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,3 @@ -This fork is created to provide a better and correct example of fine-uploader server side nodejs example - - # Server-Side Examples for the Widen Fine Uploader Javascript Library # [![license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](LICENSE)