Skip to content

Commit 4febdf4

Browse files
committed
add demo
1 parent 1debce8 commit 4febdf4

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

demo/demo.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ function abortUploadTask() {
420420
});
421421
}
422422

423+
var TaskId
423424
function sliceUploadFile() {
424425
// 创建测试文件
425426
var filename = '10mb.zip';
@@ -431,7 +432,9 @@ function sliceUploadFile() {
431432
Region: config.Region,
432433
Key: filename, /* 必须 */
433434
FilePath: filepath, /* 必须 */
434-
SliceSize: 1024 * 1024, //1MB /* 非必须 */
435+
TaskReady: function (tid) {
436+
TaskId = tid;
437+
},
435438
onHashProgress: function (progressData) {
436439
console.log(JSON.stringify(progressData));
437440
},
@@ -445,6 +448,30 @@ function sliceUploadFile() {
445448
});
446449
}
447450

451+
function cancelTask() {
452+
sliceUploadFile();
453+
setTimeout(function () {
454+
cos.cancelTask(TaskId);
455+
console.log('canceled');
456+
}, 2000);
457+
}
458+
459+
function pauseTask() {
460+
sliceUploadFile();
461+
setTimeout(function () {
462+
cos.pauseTask(TaskId);
463+
console.log('paused');
464+
restartTask();
465+
}, 2000);
466+
}
467+
468+
function restartTask() {
469+
setTimeout(function () {
470+
cos.restartTask(TaskId);
471+
console.log('restart');
472+
}, 4000);
473+
}
474+
448475
getService();
449476
// getAuth();
450477
// putBucket();
@@ -475,3 +502,6 @@ getService();
475502
// deleteMultipleObject();
476503
// abortUploadTask();
477504
// sliceUploadFile();
505+
// cancelTask();
506+
// pauseTask();
507+
// restartTask();

sdk/task.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var initTask = function (cos) {
5858
var waiting = task && task.state === 'waiting';
5959
var running = task && (task.state === 'checking' || task.state === 'uploading');
6060
if (waiting || running) {
61-
if (switchToState === 'paused' && typeof task.params.Body.pipe === 'function') {
61+
if (switchToState === 'paused' && task.params.Body && typeof task.params.Body.pipe === 'function') {
6262
console.error('stream not support pause');
6363
return;
6464
}

0 commit comments

Comments
 (0)