MConverter Home
Blog
MConverter in Android's Share Sheet

Using the Web Share Target API in File Converter PWA

Allowing for a new, easier way to choose files – previously inaccessible for web apps. Learn how to receive files from other apps.
Technical

This article originally appeared on our Medium blog.

The Web Share Target API, part of Chromium’s Project Fugu to expand the web capabilities, has opened a new entry point for returning visitors of the MConverter PWA. Instead of having to first open the PWA and then choose files through the boring file picker, users can directly share a file for converting from another app, such as a file manager. See the demo (or try it yourself):

Once installed (or added to the home screen), the MConverter PWA shows up as a native app

Increased productivity and more returning visitors

Being able to convert files from any app is much more convenient and it feels more native. Users are also exposed to the PWA from another place in addition to the home screen: the share sheet. This has led to more returning visitors, with nearly a quarter of all daily conversions getting initiated through the share menu, thanks to the Share Target API!

How to implement it?

Adding support is relatively straightforward by following this article on web.dev. In essence, you need to announce support for receiving shares in your PWA’s manifest.json:

{
    "name": "MConverter",
    ...
    "share_target": {
        "action": "/?homescreen=1&share-target=1",
        "method": "POST",
        "enctype": "multipart/form-data",
        "params": {
            "files": [
                {
                "name": "file",
                "accept": ["image/png", ".png"]
                }
            ]
        }
    }
}

Note: In contrast to the <input type="file">’s accept attribute, here it is very important to include both the MIME type and the file extension. Otherwise, by adding only a file extension, you may run into a nasty issue on Chrome for Android where the PWA appears in the share sheet, but it sometimes cannot receive the shared file. Instead, the service worker’s event.request.formData() throws the following error: Uncaught (in promise) TypeError: Failed to fetch.

Next, your service worker needs to process the shared file. In the fetch event handler, add the following snippet:

//service-worker.js:

self.addEventListener('fetch', (event) => {
    const url = new URL(event.request.url);
    if (event.request.method === 'POST' && url.pathname === '/' && url.searchParams.has('share-target')) {
        event.respondWith(Response.redirect('/?receiving-file-share=1'));

        event.waitUntil(async function () {
            const client = await self.clients.get(event.resultingClientId);
            const data = await event.request.formData();
            const files = data.get('file');
            client.postMessage({ files });
        }());
        return;
    }

    ...

});

The shared file will be made accessible via postMessage() to your website’s “regular” JavaScript code, where you can intercept and handle it the same way as a file from <input type="file">:

//script in index.html:

navigator.serviceWorker.addEventListener('message', function (e) {
    if (searchParams.has('receiving-file-share')) {
        console.log(e.data.files); //contains the file(s)
    }
});

But can you share multiple files at once?

Yes! With this little tweak I found from a helpful answer by Jeff Posnick, who is part of Google’s DevRel team, we can process many files from a single share. How convenient!

const files = data.getAll('file');

This will return all files in an array.

Next up: “Open With…” menu integration

Having quicker access to the converter PWA from other apps on Android is great, but what about desktop platforms?

The File Handling API is also part of Chrome’s Project Fugu to bring more capabilities to the web. It will allow an installed PWA to register as a potential handler for a file type.

“Open With…” context menu in File Explorer on Windows 10

In other words, the PWA will appear in the “Open With” menu of file managers on Windows, Mac, Linux and Chrome OS.

Even though it is currently only behind a developer flag, MConverter already has a (mostly complete) implementation for it. So, we are just waiting for the File Handling API to ship officially, in order to make the functionality available without needing to manually flip the switch in chrome://flags.


Animation of MConverter appearing in Android's share sheet


Check out more articles

online convert files

Top 5 Reasons Why You Need to Choose a Premium Plan with MConverter

What is the best premium plan for a converter and why do you need a subscription? Learn more in this article!
Screenshot of iPhone showing that “MConverter” will open in your default browser from now on

Important information for iOS users in the EU

Apple was about to break installable web apps in iOS 17.4, leading to local data loss. See what would've changed and why.
Right-click context menu on Windows 10, showing MConverter as an option

Convert right from your file manager | File Handling API

MConverter can now be used via the right-click menu option to “Open with…”
My Account
Profile Picture
...
Free Edition
Action required
Downloads blocker detected
To stop seeing this message,
turn off Block automatic downloads
in Samsung Internet's Browsing pivacy dashboard settings.
To continue downloading your converted files, press the following button:
Download Files
Save to folder • BETA
Currently downloading
Downloaded to ...
Google Drive File Picker
Conversion History

To access files you have converted in the past during previous sessions,
you need to:

Legal Information & Contact Details
Privacy Policy
Refund Policy
Settings


Share with other apps

Getting your file in order to share it with other apps...

Terms of Use
Large file conversions are locked

Unlock converting files over

OR
To watch an ad, disable your ad blocker and reload this page.
Upgrade

Get more features

with our Premium plans

Free

  • Convert 2 files at once
  • 100 MB maximum file size
  • 10 conversions per day
    • May be reduced to 1 depending on use
Free Gift Get 10 bonus conversions

Plus

Formerly Premium

  • Convert 250 files at once
  • 1 GB maximum file size
  • Unlimited conversions per day
  • No ads
  • Money-back guarantee Terms apply, see Refund Policy
  • No branding in file names Learn more about branding in file names
  • Access conversion history
  • Human customer support

Pro

New!

  • Convert 750 files at once
  • 2 GB maximum file size
  • Unlimited conversions per day
  • No ads
  • Money-back guarantee Terms apply, see Refund Policy
  • No branding in file names Learn more about branding in file names
  • Access conversion history
  • Priority human customer support
Monthly
Yearly
3 free months with yearly billing

MConverter is used at

Google Nvidia

What our customers say

David I.
Dec 20, 2023
I recently stumbled upon MConverter, and let me tell you, it has been an absolute game-changer for me. If you're looking for a versatile, low-cost solution for all your conversion needs, this Swiss Army knife of a tool is a must-have!
I can't recommend MConverter enough. It has become an indispensable tool in my toolkit, streamlining my work and allowing me to focus on what truly matters.
Whitney
Dec 6, 2021
This app is exactly what I asked for and is super easy to use. I am not a big time computer wizard so I need apps that do what they say do in a straightforward process. This app does just that! I love it and will continue to use it and will advise others or it as well. Good job to the owners/writers! And, sincere THANK YOU!
Antonio Hurtado
Mar 16, 2022
The most fantastic, fastest, best and easiest file converter I have ever had installed on my mobile. You deserve all the praise possible, more than happy, I am super grateful, I will always be grateful to you for this super fantastic application. This super fantastic app has literally saved my life, now I can read novels and books in any format, including pdf, which has very small print, in epub format 🌟🌟🌟🌟🌟 Thank you very much👏👍🤝😊❤️
matt32
Apr 6, 2023
AMAZING! This is the perfect file converter! The first thing I used it for was to convert WMV files to MP4 and it worked flawlessly. I then realized it supports all kinds of formats and is basically unlimited. The UI is very user-friendly and super easy to navigate. Incredible app, MConverter!
지나가던인간
Sep 22, 2021
(translated)
Although there are occasional errors, I was very impressed with the efforts of the developers to receive feedback from users and to improve the inconveniences quickly. I will be using it more often in the future.
Scott
Apr 28, 2022
I grab the webm I want to move to my phone and drag it over to the app, I click the type of file I want the webm converted to (mp4), it does it in 10 seconds. easiest 5/5 of my life.

Frequently asked questions

Can I use it on multiple devices?

Yes, you can use the paid versions of MConverter on all your devices. Just sign in with the same account.

Can I pay for just 1 month?

Yes, after subscribing to a monthly plan, simply cancel your subscription so that you are not charged again.

What is the difference between "Buy" and "Subscribe"?

A "Buy" package grants you access for a limited period, e.g., a day. On the next day, you can purchase it again if needed. "Buy" packages do not automatically renew.

Subscriptions give you continuous access to a plan. They automatically renew on a monthly or yearly basis, unless you cancel.

When can I cancel my subscription?

You can cancel your subscription anytime. Your benefits will remain active until the end of the current billing period.

Are there any fees for cancelling my subscription?

No, you can cancel your subscription for free.

Are these auto-renewing subscriptions?

No, all prices are for one-off payments. They do not automatically renew. You pay only for the period you need.
Already purchased?
Payments are processed by .

Verifying Your Payment

This may take a second...