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..8978c3c0 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'), 10); 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'), 10); + api.log("X-Last-Known-Byte: " + lkb); + if (lkb) { + data.end = lkb; + } + data.file.FileAPIReadPosition = data.end; + setTimeout(function () { _this._send(options, data); }, 0);