如何取消Google Drive API上传?

时间:2014-02-06 08:10:27

标签: c# api windows-phone-8 google-drive-api

我正在开发一个使用驱动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();

1 个答案:

答案 0 :(得分:0)

根据以下答案(Google drive SDK: Cancel upload),似乎谷歌仍然存在此问题“尚未解决”。

如果需要,ax找到了解决方案。