0

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.

steampowered
  • 11,809
  • 12
  • 78
  • 98
  • are you able to set the content-disposition at the same time you set the mime type? eg Content-Disposition: attachment; filename=filename.pdf – Paul Jowett Jan 20 '20 at 02:17
  • @PaulJowett Yes, but setting the Content-Disposition does not resolve the error. – steampowered Jan 20 '20 at 17:45
  • That's a shame. Sorry it didn't help. – Paul Jowett Jan 23 '20 at 02:10
  • There is a similar StackOverflow question [here](https://stackoverflow.com/questions/6587393/resource-interpreted-as-document-but-transferred-with-mime-type-application-zip), but none of the answers solve my problem specifically (and the question is different). – steampowered Jan 29 '20 at 20:51

0 Answers0