从googledrive

时间:2015-09-29 16:19:31

标签: c# google-drive-api google-api-dotnet-client

我需要创建一种方法,在服务帐户下从GoogleDrive恢复大文件的可恢复性。我使用Google.Apis.Drive.v2,Google.Apis.Auth和Google.Apis.Oauth2.v2在.Net 4.0中创建了一个独立的应用程序。

我目前的代码是:

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);
}

但GetStreamAsync似乎不支持指定范围参数。

一些建议建议使用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();

问题在于我不知道如何从DriveService或ServiceAccountCredential获得IAuthenticator身份验证器。它似乎也使用HttpWebRequest更慢。

0 个答案:

没有答案