c# - 下载速度低 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;
}
解决方案
推荐阅读
- javascript - 在反应导航中将道具很好地传递到屏幕
- javascript - 添加 javascript 选择器
- typescript - 这个 TypeScript 函数的正确返回类型是什么?
- swift - 查询 Firestore 数据库的日期范围
- angular - 如何处理 Firebase 身份验证状态的响应时间
- javascript - 基于旧数据的预测/预测
- javascript - 再次运行 puppeteer 函数直到完成
- python - 流连接丢失:AssertionError(('_AsyncTransportBase._produce() tx 缓冲区大小下溢', -275, 1),)
- c++ - 如何将文件发送到服务器
- java - 如何清除 EditText 中的文本?