Search code examples
c#google-drive-api

File downloaded from gdrive is corrupted


I have a problem downloading file from gdrive

I am using this code

 DriveService service = new DriveService();

            var Stream = service.HttpClient.GetStreamAsync("https://drive.google.com/open?id=blablabla");
            var result = Stream.Result;
            using (var fileStream = System.IO.File.Create("MyFile.exe"))
            {
                result.CopyTo(fileStream);
            }

But I am getting size of 103kB in MyFile.exe, and it has 800 kB.

I suspect that I am not getting download url right, as I right click on the file I want to download and get shareable link in this format: https://drive.google.com/open?id=blablaid


Solution

  • According to www.labnol.org/internet/direct-links-for-google-drive/28356/ the Google Drive download link is https://docs.google.com/uc?export=download&id=[FILE_ID].

    Otherwise you could also look at the Google Drive REST API (developers.google.com/drive/v3/web/manage-downloads).