w3c / web-share-target

Web API proposal for receiving shared data
https://w3c.github.io/web-share-target/
Other
191 stars 20 forks source link

Support file sharing #53

Closed ewilligers closed 5 years ago

ewilligers commented 6 years ago

Web Share Target now allows targets to specify that they accept files.


Preview | Diff

raucao commented 6 years ago

A POST request to a pre-defined endpoint is not sufficient in my opinion, as it would exclude all client-side apps (a.k.a. PWAs) from being a share target. Or maybe I understand this wrong?

ewilligers commented 6 years ago

A POST request to a pre-defined endpoint is not sufficient in my opinion, as it would exclude all client-side apps (a.k.a. PWAs) from being a share target.

PWAs can still be share targets and handle shares client-side. I implemented a demo, see the service worker's fetch handling code.

Ignoring control flow complications from promises, we essentially have

const formData = await event.request.formData();
const files = formData.getAll(...);  // sequence of File objects
...
  const fileReader = new FileReader();
  fileReader.onload = ...;
  fileReader.readAsText(..., 'UTF-8');
raucao commented 6 years ago

Ah, I didn't know SW could handle posted form data. Thanks!

ewilligers commented 5 years ago

Rebased to Level 2, comments addressed.