Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smarter upload recovery #86

Merged
merged 2 commits into from
Apr 19, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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