Reputation: 2029
I'm trying to upload a file to google drive and monitor the upload progress. I'm using .net with api v2.
I was using the DriveService.Files.Insert method that gives me a FilesResource.InsertMediaUpload, and then I'm using the ProgressChanged event to list to the progress. The problem is that this event is called only 3 times: with "starting", "uploading", "completed" states. I would like to have many call in the "uploading" state.
Here is my code:
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) {}
}
There's some content on internet about the ResumableUpload class in older apis, but don't know how to use that in v2. I've found the ResumableUpload class in Google.Apis.Upload namespace, but it's abstract and I have no idea how to use that.
I didn't find anything usefull about progress monitoring in documentation: https://developers.google.com/drive/manage-uploads
And I really don't want to use resumable upload through WebRequest, is there a way to implement that in .net sdk...
Upvotes: 0
Views: 1889
Reputation: 15004
The ProgressChanged
event is only triggered every time a complete chunk of data is sent to the API. If you reduce the chunk size or if the file is much larger than the default chunk size, you'll see the event being triggered multiple times.
Upvotes: 1