Show / Hide Table of Contents

Class MediaDownloader

A media downloader implementation which handles media downloads.

Inheritance
object
MediaDownloader
Implements
IMediaDownloader
Inherited Members
object.Equals(object)
object.Equals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
object.ReferenceEquals(object, object)
object.ToString()
Namespace: Google.Apis.Download
Assembly: Google.Apis.dll
Syntax
public class MediaDownloader : IMediaDownloader

Constructors

MediaDownloader(IClientService)

Constructs a new downloader with the given client service.

Declaration
public MediaDownloader(IClientService service)
Parameters
Type Name Description
IClientService service

Fields

MaximumChunkSize

Maximum chunk size. Default value is 10*MB.

Declaration
public const int MaximumChunkSize = 10485760
Field Value
Type Description
int

Properties

ChunkSize

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.

Declaration
public int ChunkSize { get; set; }
Property Value
Type Description
int

ModifyRequest

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

Declaration
public Action<HttpRequestMessage> ModifyRequest { get; set; }
Property Value
Type Description
System.Action<T><System.Net.Http.HttpRequestMessage>

Range

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

Declaration
public RangeHeaderValue Range { get; set; }
Property Value
Type Description
System.Net.Http.Headers.RangeHeaderValue

ResponseStreamInterceptorProvider

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.

Declaration
public Func<HttpResponseMessage, StreamInterceptor> ResponseStreamInterceptorProvider { get; set; }
Property Value
Type Description
System.Func<T, TResult><System.Net.Http.HttpResponseMessage, Google.Apis.Http.StreamInterceptor>

Methods

Download(string, Stream)

Downloads synchronously the given URL to the given stream.

Declaration
public IDownloadProgress Download(string url, Stream stream)
Parameters
Type Name Description
string url
System.IO.Stream stream
Returns
Type Description
IDownloadProgress

DownloadAsync(string, Stream)

Downloads asynchronously the given URL to the given stream.

Declaration
public Task<IDownloadProgress> DownloadAsync(string url, Stream stream)
Parameters
Type Name Description
string url
System.IO.Stream stream
Returns
Type Description
System.Threading.Tasks.Task<TResult><IDownloadProgress>

DownloadAsync(string, Stream, 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.

Declaration
public Task<IDownloadProgress> DownloadAsync(string url, Stream stream, CancellationToken cancellationToken)
Parameters
Type Name Description
string url
System.IO.Stream stream
System.Threading.CancellationToken cancellationToken
Returns
Type Description
System.Threading.Tasks.Task<TResult><IDownloadProgress>
Remarks

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

OnDataReceived(byte[], int)

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

Declaration
protected virtual void OnDataReceived(byte[] data, int length)
Parameters
Type Name Description
byte[] data

Byte array containing the data downloaded.

int length

Length of data downloaded in this chunk, in bytes.

OnDownloadCompleted()

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

Declaration
protected virtual void OnDownloadCompleted()

OnResponseReceived(HttpResponseMessage)

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

Declaration
protected virtual void OnResponseReceived(HttpResponseMessage response)
Parameters
Type Name Description
System.Net.Http.HttpResponseMessage response

HTTP response received.

Remarks

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

Events

ProgressChanged

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

Declaration
public event Action<IDownloadProgress> ProgressChanged
Event Type
Type Description
System.Action<T><IDownloadProgress>

Implements

IMediaDownloader
In This Article
Back to top Generated by DocFX