Skip to content

Commit 9e7df21

Browse files
committed
Merge pull request #26 from qiniupd/8165_continue_uploading_when_web_failed
add resume upload feature
2 parents b3401c1 + a786b2b commit 9e7df21

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

src/qiniu.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ function QiniuJsSDK() {
306306

307307
plupload.extend(option, op, {
308308
url: 'http://upload.qiniu.com',
309-
chunk_size: 0,
310309
multipart_params: {
311310
token: ''
312311
}
@@ -378,8 +377,17 @@ function QiniuJsSDK() {
378377
if (file.size < chunk_size) {
379378
directUpload(up, file, that.key_handler);
380379
} else {
380+
var localFileInfo = localStorage.getItem(file.name);
381381
var blockSize = chunk_size;
382-
ctx = '';
382+
if (localFileInfo) {
383+
localFileInfo = JSON.parse(localFileInfo);
384+
file.loaded = localFileInfo.offset;
385+
file.percent = localFileInfo.percent;
386+
ctx = localFileInfo.ctx;
387+
if (localFileInfo.offset + blockSize > file.size) {
388+
blockSize = file.size - localFileInfo.ctx;
389+
}
390+
}
383391
up.setOption({
384392
'url': 'http://upload.qiniu.com/mkblk/' + blockSize,
385393
'multipart': false,
@@ -407,7 +415,12 @@ function QiniuJsSDK() {
407415
'url': 'http://upload.qiniu.com/mkblk/' + leftSize
408416
});
409417
}
410-
418+
localStorage.setItem(file.name, JSON.stringify({
419+
ctx: ctx,
420+
percent: file.percent,
421+
total: info.total,
422+
offset: info.offset
423+
}));
411424
});
412425

413426
uploader.bind('Error', (function(_Error_Handler) {
@@ -565,7 +578,7 @@ function QiniuJsSDK() {
565578
if (ajax.status === 200) {
566579
var info = ajax.responseText;
567580
last_step(up, file, info);
568-
581+
localStorage.removeItem(file.name);
569582
} else {
570583
uploader.trigger('Error', {
571584
status: ajax.status,

0 commit comments

Comments
 (0)