I am trying to share file with Web Share API Level 2 with the following code:
var file = new File(["foo"], "foo.txt", {
type: "text/plain",
});
window.navigator.share({
text: "Share text",
title: "Share title",
files: [file]
})
Unfortunately, file not shared with iPhone, but successfully shared on Android.
Any solution for that?
Thanks in advance.
I got file sharing working. But on Whatsapp + iOS it only works if text and title content empty (only send the file).
let data = {};
if (files.length > 0) {
data.files = files;
}
if (title !== '')
data.title = title;
if (text !== '')
data.text = text;
if (url !== '')
data.url = url;
error.textContent = '';
navigator.share(data)
.then(() => {
})
.catch((err) => {
console.log('Unsuccessful share');
error.textContent = 'Share failed: ' + err.message;
});
https://jsfiddle.net/2q36fhb9/1/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With