Retrieve BLOB From Azure Blob Storage

Quick method to retrieve a set of BLOBs for Azure Blob Storage, given their names.
Unfortunately the Azure REST APIs don't allow, yet, to BULK retrieve the content of several BLOBs in one single call, so we need to loop over each BLOB and retrieve the content one by one
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
public static Dictionary<Guid, byte[]> GetBlobs(List<string> names) { Dictionary<string, byte[]> result = new Dictionary<string, byte[]>(); // retrieve info about the interesting BLOBs: IEnumerable<CloudBlob> blobs = s_defaultContainer.ListBlobs(). OfType<CloudBlob>().Where(c => names.Contains(c.Name)); // loop over the retrieved BLOBs: foreach (CloudBlob b in blobs) { b.FetchAttributes(); //otherwise we cannot query for Properties... byte[] res = new byte[b.Properties.Length]; // download the actual content: b.DownloadToByteArray(res, 0); result.Add(b.Name, res); } return result; }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus