public class MediaDownloader : object, IMediaDownloader
A media downloader implementation which handles media downloads.
Implements
IMediaDownloaderNamespace
Google.Apis.DownloadAssembly
Google.Apis.dll
Constructors
MediaDownloader(IClientService)
public MediaDownloader(IClientService service)
Constructs a new downloader with the given client service.
Parameter | |
---|---|
Name | Description |
service | IClientService |
Fields
MaximumChunkSize
public const int MaximumChunkSize = null
Maximum chunk size. Default value is 10*MB.
Field Value | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
Int32 |
ModifyRequest
public Action<HttpRequestMessage> ModifyRequest { get; set; }
Gets or sets the callback for modifying requests made when downloading.
Property Value | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
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 | |
---|---|
Type | Description |
Func<HttpResponseMessage, StreamInterceptor> |
Methods
Download(String, Stream)
public IDownloadProgress Download(string url, Stream stream)
Downloads synchronously the given URL to the given stream.
Parameters | |
---|---|
Name | Description |
url | String |
stream | Stream |
Returns | |
---|---|
Type | Description |
IDownloadProgress |
DownloadAsync(String, Stream)
public Task<IDownloadProgress> DownloadAsync(string url, Stream stream)
Downloads asynchronously the given URL to the given stream.
Parameters | |
---|---|
Name | Description |
url | String |
stream | Stream |
Returns | |
---|---|
Type | Description |
Task<IDownloadProgress> |
DownloadAsync(String, Stream, CancellationToken)
public 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 | |
---|---|
Name | Description |
url | String |
stream | Stream |
cancellationToken | CancellationToken |
Returns | |
---|---|
Type | Description |
Task<IDownloadProgress> |
In case the download fails Exception will contain the exception that cause the failure. The only exception which will be thrown is 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 | |
---|---|
Name | Description |
data | Byte[] Byte array containing the data downloaded. |
length | Int32 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 | |
---|---|
Name | Description |
response | HttpResponseMessage HTTP response received. |
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 | |
---|---|
Type | Description |
Action<IDownloadProgress> |