moberwasserlechner / capacitor-filesharer

Capacitor plugin to download and share files for the Web, Android and iOS! Stop the war in Ukraine!
MIT License
82 stars 20 forks source link

Bug: Instagram won't appear in the share dialog for my app, but will appear for other apps with the same file #47

Closed jonathands closed 1 year ago

jonathands commented 1 year ago

Capacitor version:

Run npx cap doctor:

Latest Dependencies:

@capacitor/cli: 4.7.1 @capacitor/core: 4.7.1 @capacitor/android: 4.7.1 @capacitor/ios: 4.7.1

Installed Dependencies:

@capacitor/cli: 4.7.0 @capacitor/core: 4.7.0 @capacitor/android: 4.7.0 @capacitor/ios: 4.7.0

Library version:

Your Plugin Configuration

Affected Platform(s):

Current Behavior

Share dialog won't show Instagram , but shows WhatsApp , when I try to share the same image from withing email or WhatsApp instagram appears normally

Expected Behavior

Instagram should be displayed on the share dialog

Sample Code or Sample Application Repo

Everything is default

Reproduction Steps

call the share dialog in a phone with instagram installed

  const handleShare = (m) => {
    async function share() {
      if (!url.match(/^[a-zA-Z]+:\/\//)) {
        url = "http://" + url;
      }
      let nurl = url.replace(/^(https?:\/\/)?(www\.)?/i, "$1www.") ;

      await fetch(nurl)
        .then(res => {
          return res.blob()
        })
        .then(blob => {
          return blob.arrayBuffer();
        })
        .then(ab => {
          const uint8Array = new Uint8Array(ab);

          var chunkSize = 1024;
          var str = '';
          for (var i = 0; i < uint8Array.length; i += chunkSize) {
            var chunk = uint8Array.subarray(i, i + chunkSize);
            str += String.fromCharCode.apply(null, chunk);
          }
          var base64String = btoa(str);

          FileSharer.share({
            filename: name,
            contentType: "application/png",
            base64Data: base64String,
          }).catch(error => {
            //alert("File sharing failed" + error.message);
            console.error("File sharing failed", error.message);
          });
        })
        .catch((error) => {
          alert(error);
        });

    }
    share();
  }
jonathands commented 1 year ago

I was using the wrong content type contentType: "application/png",

the correct mimetype would be image\png