Timeout when rendering PDF files from Azure Blob Storage

Hi again,

I’ve been using the solution suggested above and putting the MemoryStream object into the ViewBag of my view. This has worked so far with most file types but seems to have issues with any pdf files. It seems to be trying to process the pdf but will time out before getting anywhere. Here’s the code I’m using:

The blobStream variable is reading a PDF from the Azure Blob Storage.

 var viewStream = new MemoryStream();
 using (Viewer viewer = new Viewer(blobStream))
 {
     HtmlViewOptions options = HtmlViewOptions.ForEmbeddedResources(
         num => viewStream, (num, stream) => { });
 
     viewer.View(options);
 }
 
 ViewBag.viewer = viewStream;

This Topic is created by vladimir.litvinchik using Email to Topic tool.

@LBuchan1

Can you please share how do you open blobStream as there are a couple of different methods to open the stream and render file e.g.

  • stream is opened for reading - the data is fetched in chunks from Azure Blob storage (not recommended)
  • file is copied into memory or to local drive (recommended)

When the data is being read by chunks it may significantly slow down the rendering since each read is a network call so we do recommend copying the whole file into memory or to a local drive and then rendering it.

The blobStream is opened using this code snippet:

        BlobServiceClient serviceClient = new BlobServiceClient(connectiionString);
        BlobContainerClient containerClient = serviceClient.GetBlobContainerClient(blobName);
        var blob = containerClient.GetBlobClient(fileName);
        var blobStream = await blob.OpenReadAsync();

Unfortunately saving the whole file onto a local drive is not possible in this scenario.

@LBuchan1

Can you please try switching to DownloadToStreamAsync and check if the issue persists?

MemoryStream stream = new MemoryStream();
await blob.DownloadToStreamAsync(stream);