I send the PDF stream from my server to the client and then display it in the <object>
on 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 works correctly, but the following warning appears on my console:
A resource is interpreted as a Document, but is transferred using an application such as MIME / pdf
Why does he think my resource should be text/html
? If I change the Content-Type
header to text/html
, this will cause the warning to go away, but this obviously causes a PDF rendering problem. Any help would be appreciated.
saadq source share