/// <summary>
        /// Downloads the BLOB as byte array.
        /// </summary>
        /// <param name="blobName">Name of the BLOB.</param>
        /// <returns>The array of bytes of the BLOB.</returns>
        public async Task <byte[]> DownloadBlobAsByteArray(string blobName)
        {
            try
            {
                CloudBlobContainer container = BlobClient.GetContainerReference(_containername);
                CloudBlockBlob     blob      = null;
                Uri result;
                if (Uri.TryCreate(blobName, UriKind.Absolute, out result))
                {
                    blob = (CloudBlockBlob)await BlobClient.GetBlobReferenceFromServerAsync(result);
                }
                else
                {
                    blob = container.GetBlockBlobReference(blobName);
                }
                await blob.FetchAttributesAsync();

                byte[] fileByteArray = new byte[blob.Properties.Length];
                await blob.DownloadToByteArrayAsync(fileByteArray, 0);

                return(fileByteArray);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Example #2
0
 private async Task <ICloudBlob> GetBlobReference(Uri uri)
 => await BlobClient.GetBlobReferenceFromServerAsync(uri);