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:
Here is the response header from our Web API app:
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:
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.
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);