EddyVerbruggen / SocialSharing-PhoneGap-Plugin

👨‍❤️‍💋‍👨 Cordova plugin to share text, a file (image/PDF/..), or a URL (or all three) via the native sharing widget
MIT License
1.78k stars 906 forks source link

Automatically detect mime type #165

Open neuberoliveira opened 9 years ago

neuberoliveira commented 9 years ago

I found a little bug when sharing files, in SocialSharing.java you put this line: // we're assuming an image, but this can be any filetype you like String localImage = image; sendIntent.setType("image/*");

But when i try to share an audio file with whatsapp i receive a message from whatsapp like this "The file is not an image" so i changed the code to: sendIntent.setType("audio/*");

With this change whatsapp receive the audio with no problems. But if i try to share an image it says "The file is not an audio".

I think that would be nice if the plugin detect the mime type automatically.

Thanks.

EddyVerbruggen commented 9 years ago

Indeed, flagged as enhancement, thanks!

jrevault commented 9 years ago

Hi, I worked on this point tonight cause I needed to send emails with a specific filename and the correct mime type, so I made (only on my fork for instance) a small change within the shareViaEmail, As the existing format is data:image/png;base64,R0lGODlhDAA... I have added this format (with no impacts on the current operating mecanism) : df:filename.pdf;data:application/pdf;base64,R0lGODlhDAA...

It is working in my test application, and I can push the modification if you'd like, but I only code this modification in SocialSharing.java and I am unable to change the SocialSharing.m file (I do not have IOS to test).

Do you want me to push the changes on the SocialSharing.java for this enhancement ?

Have a nice day, Julien

aldatsa commented 8 years ago

Related issues: #315, #350

mspasiuk commented 8 years ago

@jrevault do you have a working fork, with this change? Currently I'm working for Android. I changed the line tom send audio in SocialSharing.java. Do I need to rebuild the plugin? I call cordova/ionic run android, but seems changes has no effect.

jrevault commented 8 years ago

Wow, it's been a long time since I did this change :) You can find what I changed here : https://github.com/jrevault/SocialSharing-PhoneGap-Plugin/commit/fe71f7571b06d259f3342cc13f641ea7ea4e4c64#diff-f613706f2334b3dac367e28727fe4060

And yes I think you have to rebuild the plugin...

EddyVerbruggen commented 8 years ago

@jrevault Did you ever send me a PR? Seems a useful addition. I wanted to make it a bit more clean and have you pass in separate params for type and filename but in the meanwhile this looks like a useful workaround.

jrevault commented 8 years ago

@EddyVerbruggen No sorry I never did. Actually the code I wrote is generic enough to use the original file name, you should'nt have any change to do...

I just send a PR...

mspasiuk commented 8 years ago

Will work with any share method (whatsapp, messenger), or only with shareViaEmail?

jrevault commented 8 years ago

Well it shouldn't be exclusive with shareViaEmail, but I haven't test with whatsapp or messenger. And as I rewrote my app in full Android, I'm not able to test it anymore....

PavanKrishna1987 commented 7 years ago

@EddyVerbruggen, @jrevault The mime type format suggested by @jrevault works great in Android. But the same causes app crash in iOS. What ia the equivalent change that I need to make in order to have it worked in iOS?

Would be of great help if I can get a solution for this. Thanks.

ncaeiro75 commented 7 years ago

@EddyVerbruggen I'm facing the same problem. All my files are shared with fixed file name when using the mime type format in iOS. It would be great to have something like Android. Anyway, is their a workaround to custom file names when sharing in iOS. Thanks'

HarelM commented 1 year ago

I think this issue is resolved, isn't it? I've looked at the code and in case you send a base64 file you can add the relevant mime type with it...