I am using Azure.Storage.Blobs version=12.4.1. I have a REST endpoint that I want to use to download blobs from a storage account.
I need to stream the result to a HttpResponseMessage and I do not want to use a MemoryStream. I want to stream the result directly to the calling client. Is there a way to achieve this. How to get the downloaded blob in the HttpResponseMessage content? I do not want to use MemoryStream, since there will be a lot of download requests.
The BlobClient class has a method DownloadToAsync but it requires a Stream as a parameter.
var result = new HttpResponseMessage(HttpStatusCode.OK);
var blobClient = container.GetBlobClient(blobPath);
if (await blobClient.ExistsAsync())
{
var blobProperties = await blobClient.GetPropertiesAsync();
var fileFromStorage = new BlobResponse()
{
ContentType = blobProperties.Value.ContentType,
ContentMd5 = blobProperties.Value.ContentHash.ToString(),
Status = Status.Ok,
StatusText = "File retrieved from blob"
};
await blobClient.DownloadToAsync(/*what to put here*/);
return fileFromStorage;
}
CreateCloudBlobClient
, which is for Legacy Azure SDK for .NET. I'll provide a more updated solution in case it is helpful for anyone using the latest Azure SDK for .NET and a later version of Azure.Storage.Blobs v12. – Ghee