【发布时间】:2014-02-06 08:10:27
【问题描述】:
我正在开发一个使用驱动器 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();
【问题讨论】:
-
取消时间长还是根本不取消?
-
我不知道如何在 Drive-sdk 中完成,但是我已经使用 HttpWebRequest 成功实现了将文件上传到谷歌驱动器并取消。如果您对此表示满意,那么我可以使用 HttpWebRequest 发布解决方案
-
也许您也可以尝试关闭流“strm”。如果有帮助
标签: c# api windows-phone-8 google-drive-api