This is a migrated thread and some comments may be shown as answers.

Load PDF From Azure

1 Answer 26 Views
PDFViewer
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Veteran
Iron
Iron
Joel asked on 07 Apr 2020, 09:30 PM

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.");
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Ivan Danchev
Telerik team
answered on 09 Apr 2020, 06:24 PM

Hello Joel,

Yes, return new FileStreamResult(stream, "application/pdf"); is a valid return type. What is the exception you get when you try to load a pdf  in the PDFViewer this way?

Regards,
Ivan Danchev
Progress Telerik

Progress is here for your business, like always. Read more about the measures we are taking to ensure business continuity and help fight the COVID-19 pandemic.
Our thoughts here at Progress are with those affected by the outbreak.
Tags
PDFViewer
Asked by
Joel
Top achievements
Rank 1
Veteran
Iron
Iron
Answers by
Ivan Danchev
Telerik team
Share this question
or