File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change @@ -420,6 +420,7 @@ function abortUploadTask() {
420420 } ) ;
421421}
422422
423+ var TaskId
423424function 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+
448475getService ( ) ;
449476// getAuth();
450477// putBucket();
@@ -475,3 +502,6 @@ getService();
475502// deleteMultipleObject();
476503// abortUploadTask();
477504// sliceUploadFile();
505+ // cancelTask();
506+ // pauseTask();
507+ // restartTask();
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments