Class MediaDownloader (1.59.0)

public class MediaDownloader : IMediaDownloader

A media downloader implementation which handles media downloads.

Inheritance

Object > MediaDownloader

Implements

IMediaDownloader

Namespace

Google.Apis.Download

Assembly

Google.Apis.dll

Constructors

MediaDownloader(IClientService)

public MediaDownloader(IClientService service)

Constructs a new downloader with the given client service.

Parameter
NameDescription
serviceIClientService

Fields

MaximumChunkSize

public const int MaximumChunkSize = 10485760

Maximum chunk size. Default value is 10*MB.

Field Value
TypeDescription
Int32

Properties

ChunkSize

public int ChunkSize { get; set; }

Gets or sets the amount of data that will be downloaded before notifying the caller of the download's progress. Must not exceed MaximumChunkSize. Default value is MaximumChunkSize.

Property Value
TypeDescription
Int32

ModifyRequest

public Action<HttpRequestMessage> ModifyRequest { get; set; }

Gets or sets the callback for modifying requests made when downloading.

Property Value
TypeDescription
Action<HttpRequestMessage>

Range

public RangeHeaderValue Range { get; set; }

The range header for the request, if any. This can be used to download specific parts of the requested media.

Property Value
TypeDescription
RangeHeaderValue

ResponseStreamInterceptorProvider

public Func<HttpResponseMessage, StreamInterceptor> ResponseStreamInterceptorProvider { get; set; }

A provider for response stream interceptors. Each time a response is produced, the provider is called, and can return null if interception is not required, or an interceptor for that response. The provider itself should not read the response's content stream, but can check headers.

Property Value
TypeDescription
Func<HttpResponseMessage, StreamInterceptor>

Methods

Download(String, Stream)

public IDownloadProgress Download(string url, Stream stream)

Downloads synchronously the given URL to the given stream.

Parameters
NameDescription
urlString
streamStream
Returns
TypeDescription
IDownloadProgress

DownloadAsync(String, Stream)

public async Task<IDownloadProgress> DownloadAsync(string url, Stream stream)

Downloads asynchronously the given URL to the given stream.

Parameters
NameDescription
urlString
streamStream
Returns
TypeDescription
Task<IDownloadProgress>

DownloadAsync(String, Stream, CancellationToken)

public async Task<IDownloadProgress> DownloadAsync(string url, Stream stream, CancellationToken cancellationToken)

Downloads asynchronously the given URL to the given stream. This download method supports a cancellation token to cancel a request before it was completed.

Parameters
NameDescription
urlString
streamStream
cancellationTokenCancellationToken
Returns
TypeDescription
Task<IDownloadProgress>
Remarks

In case the download fails Exception will contain the exception that cause the failure. The only exception which will be thrown is TaskCanceledException which indicates that the task was canceled.

OnDataReceived(Byte[], Int32)

protected virtual void OnDataReceived(byte[] data, int length)

Called when an HTTP response is received, allowing subclasses to examine data before it's written to the client stream.

Parameters
NameDescription
dataByte[]

Byte array containing the data downloaded.

lengthInt32

Length of data downloaded in this chunk, in bytes.

OnDownloadCompleted()

protected virtual void OnDownloadCompleted()

Called when a download has completed, allowing subclasses to perform any final validation or transformation.

OnResponseReceived(HttpResponseMessage)

protected virtual void OnResponseReceived(HttpResponseMessage response)

Called when a successful HTTP response is received, allowing subclasses to examine headers.

Parameter
NameDescription
responseHttpResponseMessage

HTTP response received.

Remarks

For unsuccessful responses, an appropriate exception is thrown immediately, without this method being called.

Events

ProgressChanged

public event Action<IDownloadProgress> ProgressChanged

An event which notifies when the download status has been changed.

Event Type
TypeDescription
Action<IDownloadProgress>

Extension Method