Can I share a file with Web Share API on Safari
Asked Answered
M

1

10

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.

Meilhac answered 19/2, 2020 at 14:22 Comment(7)
Forgot to mention that on iOS sharing works, but only text shared. File skipped...Meilhac
Can anyone confirm that iOS 14 is allowing files yet? Just not only textShinn
@bbullis, tested again around 3-4 weeks ago with iPhone XR 13.5.1 iOS version. Still, nothing shared except basic text.Meilhac
Confirmed iOS 14.4 still NOT sharing files. (tried both from Safari and Chrome. verified same website works on Android)Neoclassicism
Thank you @OdedBenDov for updating this!Meilhac
Hi. I got file sharing working now. But on Whatsapp + iOS it only works if text and title content are empty (only send the file).Chalaza
Thank you @GabrielSchubert. Need to test it these days, iPhone 13 is already there, webshare still not :DMeilhac
C
1

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/

Chalaza answered 1/10, 2021 at 18:52 Comment(2)
Sorry, but it's not what I need, I have to share everythingDepilatory
I tested that on Iphone 13, 15.3 IOS. File sharing worked with WhatsApp, Telegram also. I think that gives some use casesMeilhac

© 2022 - 2024 — McMap. All rights reserved.