From 59560d119ee87261b47ec3b115679a0ee65c5437 Mon Sep 17 00:00:00 2001 From: Ilya Lebedev Date: Wed, 17 Apr 2013 12:46:04 +0400 Subject: [PATCH 1/2] store file read position for smart upload restart --- lib/FileAPI.Form.js | 2 +- lib/FileAPI.XHR.js | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/FileAPI.Form.js b/lib/FileAPI.Form.js index d49c178a..fa5586e2 100644 --- a/lib/FileAPI.Form.js +++ b/lib/FileAPI.Form.js @@ -113,7 +113,7 @@ data.params.push(encodeURIComponent(file.name) + "=" + encodeURIComponent(file.blob)); } data.start = -1; - data.end = -1; + data.end = data.file.FileAPIReadPosition || -1; data.retry = 0; }); }, diff --git a/lib/FileAPI.XHR.js b/lib/FileAPI.XHR.js index 0787896b..a3d2f03d 100644 --- a/lib/FileAPI.XHR.js +++ b/lib/FileAPI.XHR.js @@ -70,6 +70,7 @@ }, _send: function (options, data){ + var _this = this, xhr, uid = _this.uid, url = options.url; api.log('XHR._send:', data); @@ -193,10 +194,10 @@ options.pause(data.file, options); // smart restart if server reports about the last known byte - var lkb = xhr.getResponseHeader('X-Last-Known-Byte'); + var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte')); api.log("X-Last-Known-Byte: " + lkb); if (lkb) { - data.end = parseInt(lkb); + data.end = lkb; } else { data.end = data.start - 1; } @@ -217,6 +218,15 @@ _this.end(xhr.status); } else { // next chunk + + // shift position if server reports about the last known byte + var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte')); + api.log("X-Last-Known-Byte: " + lkb); + if (lkb) { + data.end = lkb; + } + data.file.FileAPIReadPosition = data.end; + setTimeout(function () { _this._send(options, data); }, 0); From 90a4e1065c65fce134a5ee38ebce7683a1604073 Mon Sep 17 00:00:00 2001 From: Ilya Lebedev Date: Fri, 19 Apr 2013 15:22:16 +0400 Subject: [PATCH 2/2] added parseInt radix --- lib/FileAPI.XHR.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/FileAPI.XHR.js b/lib/FileAPI.XHR.js index a3d2f03d..8978c3c0 100644 --- a/lib/FileAPI.XHR.js +++ b/lib/FileAPI.XHR.js @@ -194,7 +194,7 @@ options.pause(data.file, options); // smart restart if server reports about the last known byte - var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte')); + var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte'), 10); api.log("X-Last-Known-Byte: " + lkb); if (lkb) { data.end = lkb; @@ -220,7 +220,7 @@ // next chunk // shift position if server reports about the last known byte - var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte')); + var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte'), 10); api.log("X-Last-Known-Byte: " + lkb); if (lkb) { data.end = lkb;