File Sharing

When using navigator.share() API, the user can customize the share behaviour based on the parameters.

If you want to share a normal text on any platform.

navigator.share({
  type: "url"
  url: "Hello World! You can open this link. 
  https://i.imgur.com/HSLFU3i.jpeg", // text or url to be shared
});

To share a file as a doc, image, etc.

navigator.share({
  type: "file"
  url: "https://i.imgur.com/HSLFU3i.jpeg",
  extension: "jpg", //extension of the file
  text: "Hello World!"// text to be shared with the file
});

Add the following parameters to share the file:

  • type: “file” or “url”

    • file: Indicate the sharing of the file

    • url: Indicate the sharing of the link

  • extension(Only for Android): When you are sharing a file, keep in mind that you add a proper extension. Don’t include a full stop while writing the extension of the file. For example, doc, docx, and pdf.

  • url: Link of the respective file or url to be shared.

  • text (Optional): A message or description of the file being shared.

Last updated

Was this helpful?