From ab9f6c6d6c5daea2ab5fd87d48e39367348e554a Mon Sep 17 00:00:00 2001 From: dolymood Date: Wed, 18 Oct 2017 21:39:45 +0800 Subject: [PATCH] checkChunkUploadedByResponse demo --- samples/Node.js/app.js | 2 +- samples/Node.js/public/app.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/samples/Node.js/app.js b/samples/Node.js/app.js index a514a9b..cf38e1c 100644 --- a/samples/Node.js/app.js +++ b/samples/Node.js/app.js @@ -43,7 +43,7 @@ app.get('/upload', function(req, res) { res.header("Access-Control-Allow-Origin", "*"); } - res.status(status == 'found' ? 200 : 404).send(status); + res.status(status == 'found' ? 200 : 204).send(status); }); }); diff --git a/samples/Node.js/public/app.js b/samples/Node.js/public/app.js index 0cba3c3..3527806 100644 --- a/samples/Node.js/public/app.js +++ b/samples/Node.js/public/app.js @@ -2,7 +2,17 @@ var r = new Uploader({ target: '/upload', chunkSize: 1024 * 1024, - testChunks: false + testChunks: true, + checkChunkUploadedByResponse: function (chunk, message) { + var objMessage = {} + try { + objMessage = JSON.parse(message) + } catch (e) {} + // fake response + // objMessage.uploaded_chunks = [2, 3, 4, 5, 6, 8, 10, 11, 12, 13, 17, 20, 21] + // check the chunk is uploaded + return (objMessage.uploaded_chunks || []).indexOf(chunk.offset + 1) >= 0 + } }); // simple-uploader.js isn't supported, fall back on a different method if (!r.support) {