Class MediaDownloader
A media downloader implementation which handles media downloads.
Inheritance
Implements
Inherited Members
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 |
---|---|
System.Int32 |
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 |
---|---|
System.Int32 |
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<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<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 |
---|---|---|
System.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 |
---|---|---|
System.String | url | |
System.IO.Stream | stream |
Returns
Type | Description |
---|---|
System.Threading.Tasks.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 |
---|---|---|
System.String | url | |
System.IO.Stream | stream | |
System.Threading.CancellationToken | cancellationToken |
Returns
Type | Description |
---|---|
System.Threading.Tasks.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 System.Threading.Tasks.TaskCanceledException which indicates that the task was canceled.
OnDataReceived(Byte[], Int32)
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 |
---|---|---|
System.Byte[] | data | Byte array containing the data downloaded. |
System.Int32 | 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<IDownloadProgress> |