【问题标题】:Download file from google drive using c#使用 C# 从谷歌驱动器下载文件
【发布时间】:2018-08-10 16:43:42
【问题描述】:

我正在尝试通过 c# 从谷歌驱动器下载文件。但是每次我运行下载文件的代码但我无法下载它。 这是我的下载代码:

private static void DownloadFile(Google.Apis.Drive.v3.DriveService driveService)
        {

            var fileId = "//my file id for file on drive";
            var request = driveService.Files.Get(fileId);
            var stream = new System.IO.MemoryStream();
            // Add a handler which will be notified on progress changes.
            // It will notify on each chunk download and when the
            // download is completed or failed.
            request.MediaDownloader.ProgressChanged +=
                (IDownloadProgress progress) =>
                {
                    try
                    {


                        switch (progress.Status)
                        {
                            case DownloadStatus.Downloading:
                                {
                                    Console.WriteLine(progress.BytesDownloaded);
                                    break;
                                }
                            case DownloadStatus.Completed:
                                {
                                    Console.WriteLine("Download complete.");
                                    break;
                                }
                            case DownloadStatus.Failed:
                                {
                                    Console.WriteLine("Download failed.");
                                    break;
                                }
                        }
                    }

                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                };
            request.Download(stream);

        }

【问题讨论】:

  • 请澄清您所说的无法下载您的错误信息是什么
  • 指定您遇到的错误
  • @DaImTo 我得到“下载失败”作为输出
  • 这就是您输出的消息,您将不得不从谷歌获得响应,并向我们表明我们无法在不知道下载失败原因的情况下对其进行调试。
  • @NitinSawant 我得到“下载失败”作为输出,我不知道它的原因。

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


【解决方案1】:

使用webContentLink 代替下载内容,或者可能是文件获取方法中的下载网址返回。您可以使用该链接下载文件。

更多信息请查看File Resource Object.

【讨论】:

    猜你喜欢
    • 2018-01-12
    • 1970-01-01
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 2021-04-05
    • 2018-07-21
    • 1970-01-01
    相关资源
    最近更新 更多