Skip to content

Commit

Permalink
Merge pull request #86 from wingedfox/master
Browse files Browse the repository at this point in the history
Smarter upload recovery
  • Loading branch information
RubaXa committed Apr 19, 2013
2 parents 2689810 + 90a4e10 commit 4743127
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/FileAPI.Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
},
Expand Down
14 changes: 12 additions & 2 deletions lib/FileAPI.XHR.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
},

_send: function (options, data){

var _this = this, xhr, uid = _this.uid, url = options.url;

api.log('XHR._send:', data);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down

0 comments on commit 4743127

Please sign in to comment.