I'm trying to download a blob from Azure Storage using the DownloadToStreamAsync()
method.
using (MemoryStream writeStream = new MemoryStream())
{
await blockBlob.DownloadToStreamAsync(writeStream);
}
I can successfully download the file, but one of the documented advantages to using this method is that you can use the data from the stream as it comes in.
How can I achieve this? How can I see the progress of the stream and, say, update the UI to show current bytes read?
Progress reporting is a feature request we previously received, but we do not have a timeline to share at this point. In the meantime, I could suggest some workarounds:
MemoryStream
and create your ownStream
class. By overriding methods likeWrite
,BeginWrite
, andWriteAsync
, you can count the number of bytes received.CloudBlockBlob.OpenRead
and get aStream
that internally downloads the blob. Then you can read in chunks and thus know how many bytes you have received so far. However, this has the disadvantage of sending more requests to the Blob service and therefore increasing the latency and cost.