Skip to content

Instantly share code, notes, and snippets.

@RachidAZ
Last active January 16, 2022 21:31
Show Gist options
  • Save RachidAZ/7d2d9946cb4ac4d62a4db05560e71051 to your computer and use it in GitHub Desktop.
Save RachidAZ/7d2d9946cb4ac4d62a4db05560e71051 to your computer and use it in GitHub Desktop.
Get azure blob as stream using SAS key
using Azure.Storage.Blobs;
using System.IO;
static internal MemoryStream GetBlobStreamUsingSAS(string AccountName , string SAS, string Container, string blobName)
{
Uri uriAddress = new Uri("https://"+AccountName+ ".blob.core.windows.net/" + SAS);
var newurl = uriAddress.Scheme + "://" + uriAddress.Host + "/" + Container + "/" + blobName + uriAddress.Query;
BlobClient blobClient = new BlobClient(new Uri(newurl), null);
var memoryStream = new MemoryStream();
var downloadBlob=blobClient.DownloadToAsync(memoryStream);
var prop=blobClient.GetProperties().Value;
var sizeBlob = prop.ContentLength;
var t=Task.Factory.StartNew(() => ReportProgressAsnyc(memoryStream.Length, sizeBlob) );
downloadBlob.Wait();
t.Wait();
return memoryStream;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment