1

I need to create a method for resumable downloads of large file from GoogleDrive under a service account. I'm creating a standalone application in .Net 4.0 using Google.Apis.Drive.v2, Google.Apis.Auth and Google.Apis.Oauth2.v2.

My current code is:

DriveService service = new DriveService(new BaseClientService.Initializer() ...
var pathString = System.IO.Path.Combine(localFilePath, fileName);
using (var fileStream = System.IO.File.Create(pathString))
{
    Task<System.IO.Stream> streamTask = service.HttpClient.GetStreamAsync(downloadURL);
    System.IO.Stream stream = await streamTask;
    await stream.CopyToAsync(fileStream);
}

However GetStreamAsync doesn't seem to support specifying a range parameter.

Some suggestions recommend using HttpWebRequest:

//Partial downloads: https://developers.google.com/drive/web/manage-downloads
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
    new Uri(file.DownloadUrl));
request.AddRange(1000, 2000);
authenticator.ApplyAuthenticationToRequest(request);
HttpWebResponse response = (HttpWebResponse) request.GetResponse();

The problem with this is I don't know how you get IAuthenticator authenticator from either DriveService or ServiceAccountCredential. It also appears using HttpWebRequest is slower.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
DerekB
  • 11
  • 1
  • [Similar to this issue](http://stackoverflow.com/questions/21017328/how-to-retrieve-partial-response-with-system-net-httpclient) – lazy Sep 29 '15 at 17:24
  • Why don't you sue the Media Downloader? More details are available here: https://developers.google.com/api-client-library/dotnet/guide/media_download – peleyal Oct 20 '15 at 17:47

0 Answers0