'HTML set a blob (PDF) url in an iframe doesn't work on mobile
I use an API to get generated PDF or stored PDF on private directory (only accessible if the user is logged in).
My endpoint send a http response with Content-Type : application/pdf
.
I receive it on React.js app that do URL.createObjectURL(blob)
from response.blob()
using fetch
.
When I push it in an iframe <iframe src={blobUrl} type="application/pdf"></iframe>
, it works on desktop browsers but not on mobile browsers.
It doesn't even work on chrome inspector in responsive mode.
But, when I download it with that code, it works on mobile :
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.style = 'display: none';
a.href = url;
a.download = filename;
document.body.appendChild(a);
a.click();
And, when I do console.log(blobUrl)
, the url is well on https : blob:https://{domain}.com/00457da4-a423-44ea-a26b-a65f7ec17e42
Did somebody know how to display PDF in an iframe for a preview on mobile ?
[EDIT] it surprisingly works on safari mobile (IOS)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|