It Is Possible To Share A File(PDF) Instead Of Url With Navigator.share?
I have a pdf file that is generated from server and I would like to allow the user to share this file via navigator.share. Is it possible to share a file instead of URL? naviga
Solution 1:
Chrome for Android (75+) now supports this feature (called Web Share API Level 2) and hopefully other browsers will follow suit soon.
A demo is available here.
Solution 2:
Chrome 93.0.4570.0 now supports sharing PDF files with Web Share. See https://chromiumdash.appspot.com/commit/7d30d42a018d4aa76fca2896f2903d892b5f5284 and https://bugs.chromium.org/p/chromium/issues/detail?id=1006055
shareButton.onclick = async () => {
const response = await fetch("https://example.com/files/hello.pdf");
const buffer = await response.arrayBuffer();
const pdf = new File([buffer], "hello.pdf", { type: "application/pdf" });
const files = [pdf];
// Share PDF file if supported.
if (navigator.canShare({ files })) await navigator.share({ files });
};
Solution 3:
If you want to share your pdf file, I will suggest that you provide them as direct links to url
property. Note that a url
of '' refers to the current page URL, just as it would in a link. Any other absolute or relative URL can also be used.
Post a Comment for "It Is Possible To Share A File(PDF) Instead Of Url With Navigator.share?"