From 4febdf4277722cd4fe35b875072fc70947481042 Mon Sep 17 00:00:00 2001 From: carsonxu <459452372@qq.com> Date: Sat, 8 Jul 2017 22:17:57 +0800 Subject: [PATCH] add demo --- demo/demo.js | 32 +++++++++++++++++++++++++++++++- sdk/task.js | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index 7a5b938..a986964 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -420,6 +420,7 @@ function abortUploadTask() { }); } +var TaskId function sliceUploadFile() { // 创建测试文件 var filename = '10mb.zip'; @@ -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)); }, @@ -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(); @@ -475,3 +502,6 @@ getService(); // deleteMultipleObject(); // abortUploadTask(); // sliceUploadFile(); +// cancelTask(); +// pauseTask(); +// restartTask(); diff --git a/sdk/task.js b/sdk/task.js index 6fcdb4d..d51aee6 100644 --- a/sdk/task.js +++ b/sdk/task.js @@ -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; }