首页 > 解决方案 > 下载速度低 Google.Apis.Drive.v3 C#

问题描述

当我使用C#中的google API下载文件时,下载速度不超过2MB / s,它可以连接到什么以及如何修复它?

我的授权和下载代码

    public async Task AuthorizeAsync()
    {
        await Task.Run(() =>
        {
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(Credentials)))
            {
                var certificate = new System.Security.Cryptography.X509Certificates.X509Certificate2(Properties.Resources.Lastrium_games_Cert, "notasecret", System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.Exportable);
                Credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(ServiceAccountEmail) { Scopes = Scopes }.FromCertificate(certificate));
            }

            Service = new DriveService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = Credential,
                ApplicationName = ApplicationName,
            });
        });
    }

    public async Task<Google.Apis.Download.IDownloadProgress> DownloadFileAsync(string fileId, Stream stream, CancellationToken cancellationToken = default)
    {
        var getRequest = Service.Files.Get(fileId);
        getRequest.MediaDownloader.ChunkSize = ChunkSize;

        getRequest.MediaDownloader.ProgressChanged += ProgressChanged;

        Google.Apis.Download.IDownloadProgress progresser = null;
        try
        {
            progresser = await getRequest.DownloadAsync(stream, cancellationToken);
        }
        catch (TaskCanceledException)
        {

        }

        getRequest.MediaDownloader.ProgressChanged -= ProgressChanged;

        return progresser;
    }

标签: c#apidownloadgoogle-drive-apilimit

解决方案


推荐阅读