I'm trying to download a blob file as a bytearray from my blob account on Azure. I do this.
var blockBlob = blobContainer.GetBlockBlobReference(id);
using (var mStream = new MemoryStream())
{
blockBlob.DownloadToStreamAsync(mStream);
result = mStream.ToArray();
}
The code above returns me a empty stream. I do have the file on my azure blob account and I checked the uri that is generated by code and it's the same that the one on my azure blob for the file I want to download as bytearray.
Is there a better way to download a azure blob file as bytearray in c#?
You should wait till the async operation gets completed.
using (var mStream = new MemoryStream())
{
await blockBlob.DownloadToStreamAsync(mStream);
result = mStream.ToArray();
}
You are getting empty because you try to get value from it when it is not yet available.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With