question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drive api v3 Can't download file

See original GitHub issue
public static void DLPC(IDownloadProgress downloadProgress)
{
      Console.WriteLine("IDownloadProgress:" + downloadProgress.Status.ToString());
}
//---------
DriveService ds = await GetGoogleDriveService("user");
var filerequest = ds.Files.Get(fileid);
Stream stream_write = new FileStream("D:\\result.txt",FileMode.CreateNew, FileAccess.Write);
filerequest.MediaDownloader.ProgressChanged += DLPC;
filerequest.Download(stream_write);

Console write “IDownloadProgress:Completed” but file size still zero

Version: 1.44.1.1876 (Latest) Framework: C# .net F 4.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
jskeetcommented, Mar 7, 2020

For the “live” part, can’t you just use the stream that your code would write into as the stream that you pass into the Download method? If that doesn’t work for you for some reason, you could potentially create your own stream implementation, but fundamentally the client library doesn’t provide any way of getting a stream that you can read from. I don’t know about the WebContentLink aspect for private files - but that wouldn’t be specific to the .NET client library anyway. For support on the general API (including the WebContentLink) I would suggest using the options listed on the Drive API support page - I’m afraid the maintainers of this repository know about the API client libraries, but not the details of each specific API.

I’ll close this issue now as I believe it’s been resolved as far as we’re able to help you, i.e. the client library aspect.

0reactions
tqk2811commented, Apr 24, 2020

@mirror222

DriveService ds =…
string uri = string.Format("https://www.googleapis.com/drive/v3/files/{0}?alt=media", fileid);
          return await GD_GetStream(uri, ds.HttpClient, start, end);

private static async Task<Stream> GD_GetStream(string uri, HttpClient httpClient, long? start, long? end)
    {
      var requestMessage = new HttpRequestMessage(HttpMethod.Get, uri);
      requestMessage.Headers.Range = new System.Net.Http.Headers.RangeHeaderValue(start, end);
      var response = await httpClient.SendAsync(requestMessage, HttpCompletionOption.ResponseHeadersRead);
      if (response.IsSuccessStatusCode) return await response.Content.ReadAsStreamAsync();
      else
      {
        if (uri.LastIndexOf("&acknowledgeAbuse=true") >= 0) throw new HttpRequestException(await response.Content.ReadAsStringAsync());
        else return await GD_GetStream(uri += "&acknowledgeAbuse=true", httpClient, start, end);
      }
    }
Read more comments on GitHub >

github_iconTop Results From Across the Web

Can not download files using Google Drive APIs V3
I'm trying to download files using Google Drive APIs V3 with alt=media option. But I can't start download in a web browser. My...
Read more >
Download & export files | Google Drive
The Google Drive API supports several types of download and export actions, as listed in the following ... System.err.println("Unable to move file: "...
Read more >
Cannot download a google drive file with the correct filename
My issue is that I cannot for the life of me figure out how to download files using the API with the correct...
Read more >
Not able to Downloading Files using Google Drive API V3
Coding example for the question Not able to Downloading Files using Google Drive API V3.
Read more >
Unable to download file via Google Drive API
In API v3 you get a promise from "drive.files.get" and on the promise resolve you have the "data" stream function downloadFile(drive, fileId, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found