public void TaskStatusDetection() { while (true) { switch (UploadTaskList.GetStatus(File.Key)) { case StatusType.RequestPause: { uploadTask.Pause(); UploadTaskList.SetStatus(File.Key, StatusType.Paused); break; } case StatusType.RequestRusume: { uploadTask.Resume(); UploadTaskList.SetStatus(File.Key, StatusType.Running); break; } case StatusType.RequestCancel: { uploadTask.Cancel(); UploadTaskList.Remove(File.Key); break; } default: break; } Thread.Sleep(500); } }
/// 上传暂停、续传、取消 public async void TransferUploadInteract() { TransferConfig transferConfig = new TransferConfig(); TransferManager transferManager = new TransferManager(cosXml, transferConfig); string bucket = "examplebucket-1250000000"; //存储桶,格式:BucketName-APPID string cosPath = "exampleobject"; //对象在存储桶中的位置标识符,即称对象键 string srcPath = @"temp-source-file"; //本地文件绝对路径 // 上传对象 COSXMLUploadTask uploadTask = new COSXMLUploadTask(bucket, cosPath); uploadTask.SetSrcPath(srcPath); await transferManager.UploadAsync(uploadTask); //.cssg-snippet-body-start:[transfer-upload-pause] uploadTask.Pause(); //.cssg-snippet-body-end //.cssg-snippet-body-start:[transfer-upload-resume] uploadTask.Resume(); //.cssg-snippet-body-end //.cssg-snippet-body-start:[transfer-upload-cancel] uploadTask.Cancel(); //.cssg-snippet-body-end }