I had this working at one point for a demo... maybe something changed? But, now I'm baking this into my site for real and pulling a PDF from Azure. I verify that I'm getting the stream. Do I have the correct return type?
if (currentContainer.Container == null)
{
var containerResponse =
await containerClient.GetAsync(
currentContainer.ContainerId);
if (containerResponse.IsSuccess)
{
currentContainer.Container =
containerResponse.Result;
}
}
if (currentContainer.Container != null)
{
CloudStorageAccount storageAccount =
CloudStorageAccount.Parse(
Glossary.Container.StorageAccountUrl);
CloudBlobClient blobClient =
storageAccount.CreateCloudBlobClient();
CloudBlobContainer container =
blobClient.GetContainerReference(
currentContainer.Container.Name);
if (await container.ExistsAsync())
{
CloudBlockBlob blob =
container.GetBlockBlobReference(
currentContainer.Path);
if (await blob.ExistsAsync())
{
// pull the zip file into memory
// load the zipFileStream from the blob
MemoryStream stream = new MemoryStream();
await blob.DownloadToStreamAsync(stream);
return new FileStreamResult(stream, "application/pdf");
}
else
{
throw new Exception("File not found in Azure container for this record");
}
}
else
{
throw new Exception(
$"Unable to capture Azure container: {currentContainer.Container.Name}");
}
}
else
{
throw new Exception($"Unable to capture recorded container for this file.");
}