Skip to content

Commit

Permalink
add demo
Browse files Browse the repository at this point in the history
  • Loading branch information
carsonxu committed Jul 8, 2017
1 parent 1debce8 commit 4febdf4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
32 changes: 31 additions & 1 deletion demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ function abortUploadTask() {
});
}

var TaskId
function sliceUploadFile() {
// 创建测试文件
var filename = '10mb.zip';
Expand All @@ -431,7 +432,9 @@ function sliceUploadFile() {
Region: config.Region,
Key: filename, /* 必须 */
FilePath: filepath, /* 必须 */
SliceSize: 1024 * 1024, //1MB /* 非必须 */
TaskReady: function (tid) {
TaskId = tid;
},
onHashProgress: function (progressData) {
console.log(JSON.stringify(progressData));
},
Expand All @@ -445,6 +448,30 @@ function sliceUploadFile() {
});
}

function cancelTask() {
sliceUploadFile();
setTimeout(function () {
cos.cancelTask(TaskId);
console.log('canceled');
}, 2000);
}

function pauseTask() {
sliceUploadFile();
setTimeout(function () {
cos.pauseTask(TaskId);
console.log('paused');
restartTask();
}, 2000);
}

function restartTask() {
setTimeout(function () {
cos.restartTask(TaskId);
console.log('restart');
}, 4000);
}

getService();
// getAuth();
// putBucket();
Expand Down Expand Up @@ -475,3 +502,6 @@ getService();
// deleteMultipleObject();
// abortUploadTask();
// sliceUploadFile();
// cancelTask();
// pauseTask();
// restartTask();
2 changes: 1 addition & 1 deletion sdk/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var initTask = function (cos) {
var waiting = task && task.state === 'waiting';
var running = task && (task.state === 'checking' || task.state === 'uploading');
if (waiting || running) {
if (switchToState === 'paused' && typeof task.params.Body.pipe === 'function') {
if (switchToState === 'paused' && task.params.Body && typeof task.params.Body.pipe === 'function') {
console.error('stream not support pause');
return;
}
Expand Down

0 comments on commit 4febdf4

Please sign in to comment.