Asynchronous download of an Azure blob to string with .NET 4.5 async, await

前端 未结 3 1939
挽巷
挽巷 2021-02-05 19:27

I\'m trying to implement a fully asynchronous blob download with .NET 4.5 async & await.

Let\'s assume the entire blob can fit in memory at once, an

3条回答
  •  别跟我提以往
    2021-02-05 20:02

    See : http://channel9.msdn.com/Events/TechEd/NorthAmerica/2013/WAD-B406#fbid=lCN9J5QiTDF for some helpful best practices including why you should avoid using Memory stream as the original code does :)

    One note is that you have two main options for downloading Blobs, the Cloud[Block|Page]Blob.Download[Range]To* methods and the stream provided by OpenRead(). In the case of the Download apis the entire blob (or range if requested) is issued as a single GET call and the results are streamed / written to the appropriate location, in the case of a transient fault the subrange of bytes not yet received is requested according to the retry policy.

    The OpenRead methods are meant for clients who wish to process data over a longer period of time and not keep a connection open. They work by specifying a given length that will be prebuffered at the client side, when the stream runs out of pre buffered data the next sub range is requested.

    Lastly, as of 2.1 RTM a DownloadTextAsync method is provided that does all of this for you :) (with optional overloads to specify encoding, default is UTF8)

提交回复
热议问题