Current implementation of FilesResource.GetRequest's DownloadAsync with range parameter doesn't expose a way to modify used MediaDownloader.
See original GitHub issueHi,
The current implementation of Google.Apis.Drive.v3.FilesResource.GetRequest
’s DownloadAsync
with a range parameter is the following:
public virtual Google.Apis.Download.IDownloadProgress DownloadRange(System.IO.Stream stream, System.Net.Http.Headers.RangeHeaderValue range)
{
var mediaDownloader = new Google.Apis.Download.MediaDownloader(Service);
mediaDownloader.Range = range;
return mediaDownloader.Download(this.GenerateRequestUri(), stream);
}
/// <summary>Asynchronously download a range of the media into the given stream.</summary>
public virtual System.Threading.Tasks.Task<Google.Apis.Download.IDownloadProgress> DownloadRangeAsync(System.IO.Stream stream,
System.Net.Http.Headers.RangeHeaderValue range,
System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
var mediaDownloader = new Google.Apis.Download.MediaDownloader(Service);
mediaDownloader.Range = range;
return mediaDownloader.DownloadAsync(this.GenerateRequestUri(), stream, cancellationToken);
}
The problem is we cannot modify the newly created mediaDownloader, for example to use ChunkSize and/or ProgressChanged event. In fact, it gives the false impression that the methods behave similar to the “non-ranged” which is not the case.
One possible workaround is to derive from GetRequest, something like this:
public class GetRequest2 : FilesResource.GetRequest
{
public event Action<IDownloadProgress> ProgressChanged;
public GetRequest2(IClientService service, string fileId)
: base(service, fileId)
{
}
public override Task<IDownloadProgress> DownloadRangeAsync(Stream stream, RangeHeaderValue range, CancellationToken cancellationToken = default)
{
var downloader = new MediaDownloader(Service);
downloader.ChunkSize = 0x10000;
downloader.Range = range;
downloader.ProgressChanged += (a) => ProgressChanged?.Invoke(a);
return downloader.DownloadAsync(GenerateRequestUri(), stream, cancellationToken);
}
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:11
Top Results From Across the Web
Google.Apis.Drive.v3.cs
... you may not use this file except in compliance with the License. ... Range = null; mediaDownloader. ... The exposure mode used...
Read more >Class MediaDownloader (1.60.0) | .NET client library
A media downloader implementation which handles media downloads. ... This can be used to download specific parts of the requested media.
Read more >lib/net45/Google.Apis.Drive.v3.xml 2.6.2
<summary>An image file and cropping parameters from which a background image for this Team Drive is set. This is a write only field;...
Read more >Download Media | API Client Library for .NET
In this implementation of resumable media download, the media content is downloaded in chunks (chunk size is configurable). Sample Code. If ...
Read more >Solved: Unable to download collector map for offline use
Solved: Hey there - new to collector and webmaps in general. Currently attempting to download a collector map for offline use and failing....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, I can see a few options here. It might be simplest to generate new overloads:
That allows more freedom in general. Will discuss with other team members.
We’ve now implemented that plan in the 1.51.0 clients.