Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Resource interpreted as Document but transferred with MIME type application/pdf

Tags:

I am sending a PDF stream from my server to the client and then displaying that PDF in an <object> tag in the client. Here is my code:

server.js

router.get('/pdf', function * () {
  var stream = getMyFileStream();
  this.set('Content-Type', 'application/pdf');
  this.response.body = stream;
});

client.js

var objectElement = document.querySelector('object');

fetch('/pdf', request)
  .then(res => res.blob())
  .then(blob => URL.createObjectURL(blob))
  .then(url => {
    objectElement.setAttribute('data', url)
    objectElement.setAttribute('type', 'application/pdf')
  })

This code seems to work correctly, however I get the following warning in my console:

Resource interpreted as Document but transferred with MIME type application/pdf

Why does it think my resource should be text/html? If I change my Content-Type header to text/html, it makes the warning go away but it obviously causes a rendering issue of the PDF. Any help would be appreciated.