As of v12, what is the recommended API to use for downloading Block Blob files?
See original GitHub issueQuery/Question What is THE way someone should be downloading files from Azure Blob Storage (block blobs) using the .NET SDK as of v12.9, in an asynchronous fashion, if the goal is to “stream” it down thru, for example, an ASP.NET controller action (REST endpoint) to a client like a browser, etc. (NOT save to a local file on server)?
There seems to be several available “download” APIs on the BlobClient, but their docs are somewhat vague or ambiguous and the MS Docs don’t seem to clarify any further:
DownloadAsync()
- marked as not browsable, but de facto way, based on all samples/blogsDownloadStreamingAsync()
DownloadContentAsync()
DownloadToAsync()
OpenReadAsync()
When I looked at the decompiled source for BlobBaseClient.DownloadAsync()
method, I see that it is decorated with [EditorBrowsable(EditorBrowsableState.Never)]
, implying that this API might slowly be on its way out, but without breaking existing code or marking as Obsolete?
I have production code that uses the BlobClient.DownloadAsync()
method to download a file from Azure Blob Storage using the Azure.Storage.Blobs nuget package v12.8, and it seems to be working just fine. However, I just upgraded the nuget package and was about to write some new code to deal with extracting zip files stored in Azure Blob…but noticed the above mentioned changes in the latest APIs of the Storage SDK.
Additionally, if trying to do some other operation that is not downloading to a browser client via a REST API, for example, if you’re unzipping a blob file and the extracted files are also going into blob storage, would one be better not downloading but instead opening it via OpenReadAsync()
?
I posted similar question on Stack Overflow and was encouraged to raise this as a question/issue here: https://stackoverflow.com/questions/68070143/azure-blob-storage-sdk-v12-blobclient-downloadasync-gone
Environment:
- Name and version of the Library package used:
Azure.Storage.Blobs
12.9.0
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:8 (4 by maintainers)
Top GitHub Comments
@tafs7 The
DownloadStreamingAsync
is replacement forDownloadAsync
. Except slightly different return type please think about this as a rename or new alias for the same functionality. We’ve introducedDownloadContentAsync
for scenarios where small sized blobs are used for formats supported byBinaryData
type (e.g. json files) thus we wanted to rename existing API to make the download family less ambiguous.The difference between
DownloadStreamingAsync
andOpenReadAsync
is that the former gives you a network stream (wrapped with few layers but effectively think about it as network stream) which holds on to single connection, the later on the other hand fetches payload in chunks and buffers issuing multiple requests to fetch content. Picking one over the other one depends on the scenario, i.e. if the consuming code is fast and you have good broad network link to storage account then former might be better choice as you avoid multiple req-res exchanges but if the consumer is slow then later might be a good idea as it releases a connection back to the pool right after reading and buffering next chunk. We recommend to perf test your app with both to reveal which is best choice if it’s not obvious.I just spent quite a while working though the blob APIs and options here to stream blobs through Azure Front Door (via ASP.NET Core) which requires range-request support. I wrote up what I think is the best solution at https://ticehurst.com/2022/01/30/blob-streaming.html (final code at the end of the article).
This did take way more research and experimenting than I expected, so if anyone can give it a quick read for any errors or misunderstandings I’d appreciate it. Thanks.