Skip to content

Commit 4743127

Browse files
committed
Merge pull request #86 from wingedfox/master
Smarter upload recovery
2 parents 2689810 + 90a4e10 commit 4743127

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

lib/FileAPI.Form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
data.params.push(encodeURIComponent(file.name) + "=" + encodeURIComponent(file.blob));
114114
}
115115
data.start = -1;
116-
data.end = -1;
116+
data.end = data.file.FileAPIReadPosition || -1;
117117
data.retry = 0;
118118
});
119119
},

lib/FileAPI.XHR.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
},
7171

7272
_send: function (options, data){
73+
7374
var _this = this, xhr, uid = _this.uid, url = options.url;
7475

7576
api.log('XHR._send:', data);
@@ -193,10 +194,10 @@
193194
options.pause(data.file, options);
194195

195196
// smart restart if server reports about the last known byte
196-
var lkb = xhr.getResponseHeader('X-Last-Known-Byte');
197+
var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte'), 10);
197198
api.log("X-Last-Known-Byte: " + lkb);
198199
if (lkb) {
199-
data.end = parseInt(lkb);
200+
data.end = lkb;
200201
} else {
201202
data.end = data.start - 1;
202203
}
@@ -217,6 +218,15 @@
217218
_this.end(xhr.status);
218219
} else {
219220
// next chunk
221+
222+
// shift position if server reports about the last known byte
223+
var lkb = parseInt(xhr.getResponseHeader('X-Last-Known-Byte'), 10);
224+
api.log("X-Last-Known-Byte: " + lkb);
225+
if (lkb) {
226+
data.end = lkb;
227+
}
228+
data.file.FileAPIReadPosition = data.end;
229+
220230
setTimeout(function () {
221231
_this._send(options, data);
222232
}, 0);

0 commit comments

Comments
 (0)