问题描述
我有一个从服务器生成的 pdf 文件,我希望允许用户通过 navigator.share 共享此文件.是否可以共享文件而不是 URL?
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?
navigator.share({
title: 'Web Fundamentals',
text: 'Check out Web Fundamentals — it rocks!',
url: 'https://developers.google.com/web',
})
.then(() => console.log('Successful share'))
.catch((error) => console.log('Error sharing', error));
推荐答案
Chrome 93.0.4570.0 现在支持通过 Web Share 共享 PDF 文件.请参阅 https://chromiumdash.appspot.com/commit/7d30d442a076a8d442a0768d442a0768d442a0768d442a068dhttps://bugs.chromium.org/p/chromium/issues/detail?id=1006055" rel="nofollow noreferrer">https://bugs.chromium.org/p/chromium/issues/detail?id=1006055
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 });
};
这篇关于是否可以与 navigator.share 共享文件(PDF)而不是 url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!