question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Current implementation of FilesResource.GetRequest's DownloadAsync with range parameter doesn't expose a way to modify used MediaDownloader.

See original GitHub issue

Hi,

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);
        }

https://github.com/googleapis/google-api-dotnet-client/blob/87fd4114950f268002345552614effb3843470c8/Src/Generated/Google.Apis.Drive.v3/Google.Apis.Drive.v3.cs#L2391

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:closed
  • Created 3 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
jskeetcommented, Feb 24, 2021

Okay, I can see a few options here. It might be simplest to generate new overloads:

public IDownloadProgress Download(Stream stream, Action<MediaDownloader> downloaderModifier)
public Task<IDownloadProgress> DownloadAsync(Stream stream, Action<MediaDownloader> downloaderModifier)

That allows more freedom in general. Will discuss with other team members.

0reactions
jskeetcommented, Mar 18, 2021

We’ve now implemented that plan in the 1.51.0 clients.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found