我正在开发一个使用驱动API在Google云端硬盘中上传文件的应用程序。我能够成功上传图片。但我的问题是,当我取消上传时,它没有被取消。我正在使用以下代码:
Google.Apis.Drive.v2.Data.File image = new Google.Apis.Drive.v2.Data.File();
//set the title of file
image.Title = fileName;
//set Mime Type of file
image.MimeType = "image/jpeg";
//set the stream position 0 because stream is readed already
strm.Position = 0;
//create a request for insert a file
System.Threading.CancellationTokenSource ctsUpload = new CancellationTokenSource();
FilesResource.InsertMediaUpload request = App.GoogleDriveClient.Files.Insert(image, strm, "image/jpeg");
request.ChunkSize = 512 * 1024;
request.ProgressChanged += request_ProgressChanged;
//visible the uploading progress
//upload file
request.UploadAsync(ctsUpload.Token);
以下代码写在取消按钮点击事件
上 ctsUpload.Cancel();