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

File sharing failed: The string contains invalid characters. #5

Closed renege closed 5 years ago

renege commented 5 years ago

Hi, I'm trying the following code on iOS:

sharePhoto() {
     var self = this;
            var img = document.getElementById('photo').attr('src');
            FileSharer.share({
                filename: Math.random()+"_pic.png",
                base64Data: img.replace('data:image/png;base64', '').replace('image/png;base64', ''),
                contentType: "image/png",
            }).then(() => {
                alert('DONE');
            }).catch(error => {
                console.error("File sharing failed:", error.message);
            });
},

I'm 100% the picture is correct, because it's shown correctly on the image src.

But it always gives me: ⚡️ [error] - File sharing failed: The string contains invalid characters.

And when I do: base64Data: img.replace('data:image/png;base64', '').replace('image/png;base64', '').replace(/\s/g, ''), It gives me: ERR_PARAM_DATA_INVALID

renege commented 5 years ago

@moberwasserlechner my ionic app is build in vue with capacitor by the way

renege commented 5 years ago

@moberwasserlechner even this fails:

    Plugins.FileSharer.share({
                filename: Math.random()+"_foo.png",
                base64Data: 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAEBgIApD5fRAAAAABJRU5ErkJggg==',
                contentType: "image/png",
            }).then(() => {
                alert('DONE');
            }).catch(error => {
                console.error("File sharing failed:", error.message);
            });

That shows the alert() and redirects me to a white screen of death.. Nothing Share-a-like about this.

moberwasserlechner commented 5 years ago

Hi,

Which versions of capacitor and ios are you using? Does it work on the Web and Android?

I try to have a look but can not make any promises.

BR, Michael

moberwasserlechner commented 5 years ago

Dataurls normally look like data:image/png;base64, + image content. See the comma at the end.

In your code above you do not replace the comma, which might cause the error?

renege commented 5 years ago

Thanks, was the comma!

loburets commented 4 years ago

Just to emphasise for other users: you don't need the data:image/png;base64, part in the base64Data parameter. So, use something like .replace(/^data:image\/[a-z]+;base64,/, "")

pratiksan45 commented 3 years ago

Or , If someone want the easiest way you can just base64Data: img.split(',')[1],

Maheshbhusanoor commented 3 years ago

FileSharer.share({ filename: "abc.png", base64Data: 'base64 string here', contentType: "image/png", }).then(() => { alert('DONE'); }).catch(error => { console.error("File sharing failed:", error.message); });

       Its showing the alert Done but nothing is happening. Can anyone help me with this? 
jake-nz commented 2 years ago

@Maheshbhusanoor Probably because Capacitor 3 is not supported :( https://github.com/moberwasserlechner/capacitor-filesharer/issues/31#issuecomment-907005914

JacquesBeets commented 1 year ago

Hey guys, confirming this issue is still happening on Capacitor 4.0.0

Jellybing commented 1 year ago

I use this plugin on Capacitor 4.0.0,the app will be closed when share image to wechat or other im,how to solve this problem,thanks.

moberwasserlechner commented 1 year ago

Please do not comment on closed issues but create a new one and provide the information the issue template asks. I will not look on closed issues when planing a new release and therefore you will not get any answers to your questions.