I have a winforms application that uses Google Drive to manage files. My file upload method is fairly simple:
public static File UploadFile(string sourcefile, string description, string mimeType, int attempt)
{
try
{
string title = Path.GetFileName(sourcefile);
var file = new File {Title = title, Description = description, MimeType = mimeType};
byte[] bytearray = System.IO.File.ReadAllBytes(sourcefile);
var stream = new MemoryStream(bytearray);
FilesResource.InsertMediaUpload request = DriveService.Files.Insert(file, stream, "text/html");
request.Convert = false;
request.Upload();
File result = request.ResponseBody;
return result;
}
catch (Exception e)
{
if(attempt<10)
{
return UploadFile(sourcefile, description, mimeType, attempt + 1);
}
else
{
throw e;
}
}
}
This works, but prior to using Google Drive, I used an FTP solution, which allowed asynchronous upload operations. I would like to include a progress bar when files are uploading, but I can't figure out if there is a way to call InserMediaUpload asynchronously. Do such capabilities exist?
Thank you.