HttpClientFileDownloader class
Namespace: Velopack.Sources
A simple abstractable file downloader
public class HttpClientFileDownloader : IFileDownloader
Implements: IFileDownloader
Constructors
| Constructor | Summary |
|---|---|
HttpClientFileDownloader |
HttpClientFileDownloader()
public HttpClientFileDownloader()
Properties
| Property | Summary |
|---|---|
UserAgent | The User-Agent sent with requests |
UserAgent
public static ProductInfoHeaderValue UserAgent { get; }
The User-Agent sent with requests
Methods
| Method | Summary |
|---|---|
DownloadFile | Downloads a remote file to the specified local path |
DownloadBytes | Returns a byte array containing the contents of the file at the specified url |
DownloadString | Returns a string containing the contents of the specified url |
TryDownloadThenLowercase<T> | Tries to download a string from the specified url. If it fails, it will attempt to |
DownloadToStreamInternal | Asynchronously downloads a remote url to the specified destination stream while |
CreateHttpClientHandler | Creates a new HttpClientHandler with default settings, used for |
CreateHttpClient | Creates a new HttpClient for every request. |
DownloadFile(url, targetFile, progress, headers, timeout, cancelToken)
public virtual Task DownloadFile(string url, string targetFile, Action<int> progress, IDictionary<string, string>? headers, double timeout, CancellationToken cancelToken = default)
Downloads a remote file to the specified local path
Parameters
| Name | Type | Description |
|---|---|---|
url | string | The url which will be downloaded. |
targetFile | string | The local path where the file will be stored If a file exists at this path, it will be overwritten. |
progress | Action<int> | A delegate for reporting download progress, with expected values from 0-100. |
headers | IDictionary<string, string> | Headers that can be passed to Http Downloader, e.g. Accept or Authorization. |
timeout | double | The maximum time in minutes to wait for the download to complete. |
cancelToken | CancellationToken | Optional token to cancel the request. |
Returns Task
DownloadBytes(url, headers, timeout)
public virtual Task<byte[]> DownloadBytes(string url, IDictionary<string, string>? headers, double timeout)
Returns a byte array containing the contents of the file at the specified url
Parameters
| Name | Type | Description |
|---|---|---|
url | string | |
headers | IDictionary<string, string> | |
timeout | double |
Returns Task<byte[]>
DownloadString(url, headers, timeout)
public virtual Task<string> DownloadString(string url, IDictionary<string, string>? headers, double timeout)
Returns a string containing the contents of the specified url
Parameters
| Name | Type | Description |
|---|---|---|
url | string | |
headers | IDictionary<string, string> | |
timeout | double |
Returns Task<string>
TryDownloadThenLowercase(downloadFunc, url)
protected virtual Task<T> TryDownloadThenLowercase<T>(Func<string, Task<T>> downloadFunc, string url)
Tries to download a string from the specified url. If it fails, it will attempt to download the string again with the url lowercased. This is useful for services that are case-sensitive yet corrupt the case on upload.
Parameters
| Name | Type | Description |
|---|---|---|
downloadFunc | Func<string, Task<T>> | |
url | string |
Returns Task<T>
DownloadToStreamInternal(client, requestUri, destination, progress, cancelToken)
protected virtual Task DownloadToStreamInternal(HttpClient client, string requestUri, Stream destination, Action<int>? progress = null, CancellationToken cancelToken = default)
Asynchronously downloads a remote url to the specified destination stream while providing progress updates.
Parameters
| Name | Type | Description |
|---|---|---|
client | HttpClient | |
requestUri | string | |
destination | Stream | |
progress | Action<int> | |
cancelToken | CancellationToken |
Returns Task
CreateHttpClientHandler()
protected virtual HttpClientHandler CreateHttpClientHandler()
Creates a new HttpClientHandler with default settings, used for
new HttpClient's. Override this function to add client certificates,
proxy configurations, cookies, or change other http behaviors.
Returns HttpClientHandler
CreateHttpClient(headers, timeout)
protected virtual HttpClient CreateHttpClient(IDictionary<string, string>? headers, double timeout)
Creates a new HttpClient for every request.
Parameters
| Name | Type | Description |
|---|---|---|
headers | IDictionary<string, string> | |
timeout | double |
Returns HttpClient
Generated from Velopack 1.1.1