【问题标题】:How to cancel upload in Google Drive API?如何在 Google Drive API 中取消上传?
【发布时间】: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


【解决方案1】:

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

万一需要斧头找到了解决办法。

【讨论】:

    猜你喜欢
    • 2020-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多