Sending compressed files to viewer gives an error

We have a Web API application that sends compressed PDF files using Brotli compression to the WebViewer on our web server.
For some reason I get this error message:
image

Here is the response header from our Web API app:
image

I also tried with application/pdf mime type, but still no luck.

Am I doing something wrong?!!

Also, even if the returned file has .br in the file name, I still see these warning:

Maybe I should send the file as .br.pdf ?!
Somebody to clarify this.

Thank you.

Hello aleksandar.angelov,

How are you loading the files? Can you provide a code snippet?

Typically we see this when the endpoint from loading the file is not returning a PDF, and requires authentication or double-checking that the endpoint does resolve in a PDF.

The brotli compression is for the PDF workers, not for the PDF files so encoding the files is not necessary.

Best regards,
Tyler

Hi,

Here is part of the code that returns the file. This code returns a PDF and works with response compression:

var bytes = await System.IO.File.ReadAllBytesAsync(pdfFilePath);

int last_pos = pdfFilePath.LastIndexOf('/');
if (last_pos > 0) pdfFilePath = pdfFilePath[(last_pos+1)..];
else pdfFilePath = "file.pdf";

return File(bytes, "application/pdf", pdfFilePath, true);

pdfFilePath is the full path. I leave only the file name for the response. It looks like this: 1_123_456.pdf
The issue with this code is that I get the 2 warnings in the Web Browser.

Then I removed response compression and I tried this code, but it didn’t work:

var bytes = await System.IO.File.ReadAllBytesAsync(brFilePath);

int last_pos = brFilePath.LastIndexOf('/');
if (last_pos > 0) brFilePath = brFilePath[(last_pos+1)..];
else brFilePath = "file.br";

return File(bytes, "application/pdf", brFilePath, true);

brFilePath is the full path to the compressed file. I leave only the file name again. It looks like this: 1_123_456.br

Then I changed the file mime type, but it doesn’t work as well:

var bytes = await System.IO.File.ReadAllBytesAsync(brFilePath);

int last_pos = brFilePath.LastIndexOf('/');
if (last_pos > 0) brFilePath = brFilePath[(last_pos+1)..];
else brFilePath = "file.br";

return File(bytes, "application/x-br", brFilePath, true);

Thank you.

Hello aleksandar.angelov,

To load a file in WebViewer, it has to be an decompressed (brotli, gz, or whatever) PDF file, if you decompress the file then load it in the view.

How you handle compression and decompression of the file when in transit is up to your design.

Best regards,
Tyler

Hi,

How to get rid of these warning messages on the browser then?
I think, I’m missing some part of the logic here.

Thank you.

The warning messages you see in the console are due to the server hosting the files not supporting BR and GZ compression.


See the guide in the warning message here: Content-encoding | Apryse Documentation for more information

Best regards,
Tyler