Class MediaDownloader
A media downloader implementation which handles media downloads.
Implements
Inherited Members
Namespace: Google.Apis.Download
Assembly: Google.Apis.dll
Syntax
public class MediaDownloader : IMediaDownloaderConstructors
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 = 10485760Field 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 | 
|---|---|
| Action<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 | 
|---|---|
| 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 | 
|---|---|
| Func<HttpResponseMessage, 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 | |
| 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 | |
| Stream | stream | 
Returns
| Type | Description | 
|---|---|
| Task<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 | |
| Stream | stream | |
| CancellationToken | cancellationToken | 
Returns
| Type | Description | 
|---|---|
| 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[], 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 | 
|---|---|---|
| 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> ProgressChangedEvent Type
| Type | Description | 
|---|---|
| Action<IDownloadProgress> |