我想上傳文件到谷歌驅動器和監控上傳進度。我使用.net和api v2。ResumableUpload與谷歌驅動器api v2 .net
我在使用DriveService.Files.Insert方法,它給了我一個FilesResource.InsertMediaUpload,然後我使用ProgressChanged事件列出了進度。問題是這個事件只被調用3次:有「開始」,「上傳」,「完成」狀態。我想在「上傳」狀態下撥打很多電話。
這裏是我的代碼:
private UploadToGoogle(...)
{
//Consider I have an populated File and MemoryStream:
MemoryStream contentStream = /*Populated memoryStream*/;
File body = /*Populated file*/;
FilesResource.InsertMediaUpload uploadRequest = null;
try
{
contentStream.Position = 0;
uploadRequest = driveService.Files.Insert(body, contentStream, body.MimeType);
uploadRequest.ProgressChanged += new Action<Google.Apis.Upload.IUploadProgress>(UploadProgessEvent);
Action asyncAction =() =>
{
uploadRequest.Upload();
Console.WriteLine("Completed!");
};
var thread = new System.Threading.Thread(new System.Threading.ThreadStart(asyncAction));
thread.Start();
}catch(Exception) {}
}
有關於老年人的API的ResumableUpload類互聯網上的一些內容,但不知道如何使用,在v2中。我在Google.Apis.Upload命名空間中找到了ResumableUpload類,但它是抽象的,我不知道如何使用它。
我沒有發現任何有用的有關進展情況的文件監控:https://developers.google.com/drive/manage-uploads
我真的不想通過WebRequest的使用斷點續傳的上傳,有沒有實現,在.NET SDK的方式...
謝謝!在使用DriveService.Files.Insert方法完成上載之前,是否可以獲取文件ID? – IPValverde
僅當上傳完成時才生成並返回文件ID –