public DownloadBlob ( |
||
uri | The blob url from which file needs to be downloaded.If blob has private read permissions then appropriate sas url need to be passed | |
localFile | string | The full path where file will be saved |
fileEncryption | Microsoft.WindowsAzure.MediaServices.Client.FileEncryption | The file encryption if file has been encrypted. Pass null if no encryption has been used |
initializationVector | ulong | The initialization vector if encryption has been used. |
cancellationToken | The cancellation token. | |
retryPolicy | IRetryPolicy | The RetryPolicy delegate returns a ShouldRetry delegate, which can be used to implement a custom retry policy.RetryPolicies class can bee used to get default policies |
getSharedAccessSignature | Func |
A callback function which returns Sas signature for the file to be downloaded |
Результат | Task |
/// <summary> /// Downloads the file asynchronously . /// </summary> /// <param name="destinationPath">The path to download the file to.</param> /// <param name="blobTransferClient">The <see cref="BlobTransferClient"/> which is used to download files.</param> /// <param name="locator">An asset <see cref="ILocator"/> which defines permissions associated with the Asset.</param> /// <param name="retryPolicy">The retry policy.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> internal Task DownloadToFileAsync(string destinationPath, BlobTransferClient blobTransferClient, ILocator locator, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { FileEncryption fileEncryption = this.GetFileEncryption(); cancellationToken.Register(() => this.Cleanup(null, fileEncryption, null, null)); return(Task.Factory.StartNew(() => { cancellationToken.ThrowIfCancellationRequested(() => this.Cleanup(null, fileEncryption, null, null)); ulong iv = Convert.ToUInt64(this.InitializationVector, CultureInfo.InvariantCulture); UriBuilder uriBuilder = new UriBuilder(locator.BaseUri); uriBuilder.Path += String.Concat("/", Name); blobTransferClient.TransferProgressChanged += this.OnDownloadBlobTransferProgressChanged; blobTransferClient.DownloadBlob( uriBuilder.Uri, destinationPath, fileEncryption, iv, cancellationToken, retryPolicy, () => locator.ContentAccessComponent) .Wait(cancellationToken); cancellationToken.ThrowIfCancellationRequested(() => this.Cleanup(null, fileEncryption, null, null)); }, cancellationToken) .ContinueWith( t => { t.ThrowIfFaulted(() => this.Cleanup(null, fileEncryption, null, null)); cancellationToken.ThrowIfCancellationRequested(() => this.Cleanup(null, fileEncryption, null, null)); this.Cleanup(null, fileEncryption, null, null); }, cancellationToken)); }
/// <summary> /// Downloads the file asynchronously . /// </summary> /// <param name="destinationPath">The path to download the file to.</param> /// <param name="blobTransferClient">The <see cref="BlobTransferClient"/> which is used to download files.</param> /// <param name="locator">An asset <see cref="ILocator"/> which defines permissions associated with the Asset.</param> /// <param name="retryPolicy">The retry policy.</param> /// <param name="cancellationToken">The cancellation token.</param> /// <returns>A function delegate that returns the future result to be available through the Task.</returns> internal Task DownloadToFileAsync(string destinationPath,BlobTransferClient blobTransferClient, ILocator locator, IRetryPolicy retryPolicy, CancellationToken cancellationToken) { FileEncryption fileEncryption = this.GetFileEncryption(); cancellationToken.Register(() => this.Cleanup(null, fileEncryption, null, null)); return Task.Factory.StartNew(() => { cancellationToken.ThrowIfCancellationRequested(() => this.Cleanup(null, fileEncryption, null, null)); ulong iv = Convert.ToUInt64(this.InitializationVector, CultureInfo.InvariantCulture); UriBuilder uriBuilder = new UriBuilder(locator.Path); uriBuilder.Path += String.Concat("/", Name); blobTransferClient.TransferProgressChanged += this.OnDownloadBlobTransferProgressChanged; blobTransferClient.DownloadBlob(uriBuilder.Uri, destinationPath, fileEncryption, iv, cancellationToken, retryPolicy).Wait(cancellationToken); cancellationToken.ThrowIfCancellationRequested(() => this.Cleanup(null, fileEncryption, null, null)); }, cancellationToken) .ContinueWith( t => { t.ThrowIfFaulted(() => this.Cleanup(null, fileEncryption, null, null)); cancellationToken.ThrowIfCancellationRequested(() => this.Cleanup(null, fileEncryption, null, null)); this.Cleanup(null, fileEncryption, null, null); }, cancellationToken); }