Web Share API File Sharing JavaScript Example
Run
<!DOCTYPE html> <html> <head> <title>Web Share Picture Sharing</title> </head> <body> <input id="files" type="file"/> <button id="share">Click to Share</button> <script> document.getElementById('share').onclick = function() { var files = document.getElementById('files'); var arrayOfFiles = files.files; if (arrayOfFiles && arrayOfFiles.length > 0) { if (navigator.canShare && navigator.canShare({files: arrayOfFiles })) { navigator.share({ files: arrayOfFiles, text: 'Some fantastic picture!', title: 'Share a fantastic picture'}) .then(() => alert('Picture sharing worked!')) .catch((err) => `Oops! Some error: ${err} occurred, picture sharing does not work.`); } } } </script> </body> </html>