Despite setting the correct MIME type, I get a warning in Chrome v79 saying:
Resource interpreted as Document but transferred with MIME type application/pdf
Trying to serve a pdf generated using pdfmake with a binary output. I set the MIME header correctly, but still Chrome gives this error.
createPdf = async () => {
const PdfPrinter = require('pdfmake');
const Promise = require("bluebird");
var pdfDoc = printer.createPdfKitDocument(docDefinition);
return new Promise((resolve, reject) =>{ try {
var chunks = [];
pdfDoc.on('data', chunk => chunks.push(chunk));
pdfDoc.on('end', () => resolve(Buffer.concat(chunks)));
pdfDoc.end();
} catch(err) {
reject(err);
}});
};
router.get('/get-pdf/:filename', async (req, res)=>{
var binaryResult = await createPdf();
res.contentType('application/pdf').send(binaryResult);
});
And the browser where the pdf is displayed inline:
<object data="/get-pdf/filename.pdf" type="application/pdf"
width="100%" height="100%"></object>
Note: Setting the Content-Disposition
at the server does not affect the error or cause the error to go away.