<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Kush Kumar on Medium]]></title>
        <description><![CDATA[Stories by Kush Kumar on Medium]]></description>
        <link>https://medium.com/@kushkumar636?source=rss-9762b36fb16e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*8HRUFvySJvcwKlI5.</url>
            <title>Stories by Kush Kumar on Medium</title>
            <link>https://medium.com/@kushkumar636?source=rss-9762b36fb16e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 11:23:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kushkumar636/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Share Image With Web Share API]]></title>
            <link>https://kushkumar636.medium.com/web-apps-share-file-text-urls-over-social-media-96ec654c0b90?source=rss-9762b36fb16e------2</link>
            <guid isPermaLink="false">https://medium.com/p/96ec654c0b90</guid>
            <category><![CDATA[share-image]]></category>
            <category><![CDATA[web-share-image]]></category>
            <category><![CDATA[web-share-api]]></category>
            <category><![CDATA[social-media-sharing]]></category>
            <category><![CDATA[image-sharing]]></category>
            <dc:creator><![CDATA[Kush Kumar]]></dc:creator>
            <pubDate>Sat, 22 May 2021 20:23:27 GMT</pubDate>
            <atom:updated>2021-05-31T19:52:12.321Z</atom:updated>
            <content:encoded><![CDATA[<p>With growing web apps and ease of use, sometimes the user needs to share the content over social media from the web app. Sharing text or URLs from a web app to social media is quite easy, but sharing the files from a web app to social media is quite tricky, to make it happen Web Share API can be used.</p><p><a href="https://w3c.github.io/web-share/demos/share-files.html"><strong>Web Share API demo</strong></a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/382/1*eDqEHLlIz1_g7Hj_YuFb8A.gif" /><figcaption>Native intent with Web Share API</figcaption></figure><p>Working with one of my recent projects I thought to share a dynamic banner with a user name where the user can share the banner over social media to show his/her contribution.</p><p>Initially, I tried to store the user banner to firebase and sharing the file URL to social media but sharing the file as the image would be more relevant than sharing an image URL. Then found the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share">Web Share API</a> which uses the user device to share the file, text, URL to social media. On the action of the user, the intent will open which will have all apps which support sharing option, out of which the user can choose to share.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*skUk6xtwFzVaVekUqPtvCg.jpeg" /><figcaption>left android intent right IOS intent</figcaption></figure><h3>Step 1</h3><p><strong>Used </strong><a href="https://www.npmjs.com/package/html-to-image"><strong>html-to-image</strong></a><strong> package to create the image</strong></p><p>With the use of the <a href="https://www.npmjs.com/package/html-to-image">html-to-image</a> package, I was able to take a portion of div with its elementId and convert that portion to base64. Package support promise so we can catch the error if it’s encountered.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.thiscodeworks.com%2Fembed%2F60b534108b8ba6001483a727&amp;dntp=1&amp;display_name=thiscodeworks&amp;url=https%3A%2F%2Fwww.thiscodeworks.com%2Fimporting-html-to-image-package%2F60b534108b8ba6001483a727&amp;image=https%3A%2F%2Fwww.thiscodeworks.com%2Fimages%2Fget-on-firefox.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=thiscodeworks" width="620" height="88" frameborder="0" scrolling="no"><a href="https://medium.com/media/b78419a2cf6a298c966973049dd66e08/href">https://medium.com/media/b78419a2cf6a298c966973049dd66e08/href</a></iframe><h3>Step 2</h3><p>dataUrlToFile is a helper function that takes base64 and the file name as parameters. It returns the temporary file location.</p><p>This helper function is used in <strong>step 4</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.thiscodeworks.com%2Fembed%2F60b5349b8b8ba6001483a729&amp;dntp=1&amp;display_name=thiscodeworks&amp;url=https%3A%2F%2Fwww.thiscodeworks.com%2F60b5349b8b8ba6001483a729&amp;image=https%3A%2F%2Fwww.thiscodeworks.com%2Fimages%2Fget-on-firefox.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=thiscodeworks" width="620" height="218" frameborder="0" scrolling="no"><a href="https://medium.com/media/459b4fa547cd8f005fc6195f22df8ada/href">https://medium.com/media/459b4fa547cd8f005fc6195f22df8ada/href</a></iframe><h3>Step 3</h3><p>shareFile is another helper function that is created to share the file along with title and text.</p><p><strong>navigator.canShare : </strong>checks the <a href="https://caniuse.com/web-share">browser support</a></p><p><strong>navigator.canShare({files: [file]})</strong> : checks whether shared file is <a href="https://docs.google.com/document/d/1tKPkHA5nnJtmh2TgqWmGSREUzXgMUFDL6yMdVZHqUsg/edit">supported</a> or not</p><p><strong>navigator.share</strong> : triggers the intent that shows all the apps that support share option</p><p>This helper function is used in <strong>step 4</strong></p><p><strong>navigator.canShare({files: [file]})</strong> checks weathe</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.thiscodeworks.com%2Fembed%2F60b534dc8b8ba6001483a72a&amp;dntp=1&amp;display_name=thiscodeworks&amp;url=https%3A%2F%2Fwww.thiscodeworks.com%2F60b534dc8b8ba6001483a72a&amp;image=https%3A%2F%2Fwww.thiscodeworks.com%2Fimages%2Fget-on-firefox.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=thiscodeworks" width="620" height="257" frameborder="0" scrolling="no"><a href="https://medium.com/media/d96ada89a951176f9bd9ebc84b43b2c9/href">https://medium.com/media/d96ada89a951176f9bd9ebc84b43b2c9/href</a></iframe><h3>Step 4</h3><p>With the elementId <strong>thanku_poster</strong> I am creating a base64 data with package <a href="https://www.npmjs.com/package/html-to-image">html-to-images</a> function toJpeg.</p><p>Once base64 is created with the dataUrlToFile helper function creating the file location.</p><p>Once the creation of file location is done shareFile helper function is called to share the content.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.thiscodeworks.com%2Fembed%2F60b5351b8b8ba6001483a72b&amp;dntp=1&amp;display_name=thiscodeworks&amp;url=https%3A%2F%2Fwww.thiscodeworks.com%2F60b5351b8b8ba6001483a72b&amp;image=https%3A%2F%2Fwww.thiscodeworks.com%2Fimages%2Fget-on-firefox.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=thiscodeworks" width="620" height="192" frameborder="0" scrolling="no"><a href="https://medium.com/media/644de11016fd56d8651116f0cbee5d50/href">https://medium.com/media/644de11016fd56d8651116f0cbee5d50/href</a></iframe><h3>Web Share API — Features and Limitations</h3><h3>Features</h3><ul><li>Web apps can use the system-provided sharing capabilities just like a platform-specific app.</li><li>Developers get a more comprehensive range of sharing options.</li><li>Web Share APIs help to share files, text, and URLs.</li></ul><h3>Limitations</h3><ul><li>It can only be used on a site that is accessed via HTTPS.</li><li>It can share, URLs, text, or files.</li><li>The intent will open on user actions on page load it can’t open</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VHltZxp-Ctdw2D3tr-G9cA.png" /><figcaption><a href="https://caniuse.com/web-share">Supported browser</a></figcaption></figure><p>References</p><ul><li><a href="https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share">https://developer.mozilla.org/en-US/docs/Web/API/Navigator/share</a></li><li><a href="https://web.dev/web-share/">https://web.dev/web-share/</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=96ec654c0b90" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>