Closed ewilligers closed 5 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?
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');
Ah, I didn't know SW could handle posted form data. Thanks!
Rebased to Level 2, comments addressed.
Web Share Target now allows targets to specify that they accept files.
Preview | Diff