Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I share a file with Web Share API on Safari

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.

like image 660
Bogdan Sizov Avatar asked Feb 19 '20 14:02

Bogdan Sizov


1 Answers

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/

like image 112
Gabriel Schubert Avatar answered Oct 10 '22 21:10

Gabriel Schubert