tauri-apps / plugins-workspace

All of the official Tauri plugins in one place!
https://tauri.app
Apache License 2.0
819 stars 223 forks source link

Plugin Request: Share Files or Data #1461

Open ecmel opened 3 months ago

ecmel commented 3 months ago

Web Share API is not available for android https://developer.mozilla.org/en-US/docs/Web/API/Web_Share_API and shell open does not work with file paths on mobile.

We need a way to make the mobile app share files or data.

flapili commented 2 months ago

Hi @ecmel , I would try to implement this

Here we only speak about sending data rigth, not be the target ?

The downside of Android's intent is the api can't be 1-1 to the web api, and the guest js should be the most platform agnostic I believe

PS: there is no way to ensure the share worked, there is no standard about that, some application respond when the handling of the file is ok, some other when the file is valid, some other only respond with errror when it's invalid... And most app never respond 😅🥹 (but accept without any issue the file)

ecmel commented 2 months ago

Hi @flapili thank you for your response, yes I am speaking about sending data not target. Specifically I need to share a pdf file stored in app data dir and view it in system's default pdf viewer or send by e-mail etc. For MacOS the shell open api works very well, for iOS web share api some what works but for android I could not find a way.

flapili commented 2 months ago

I'll try to take a look, but I'm clueless about path, I only found example when the file is sent as bytes not path

What kind of spec / DX / final API would you like to have ?

EDIT: found https://developer.android.com/reference/android/content/ContentUris

ecmel commented 1 month ago

In fact https://beta.tauri.app/reference/javascript/shell/#open function works on desktop very well, on android I get the following error. This may be a purely device permission issue and may be easy to fix.

Screenshot 2024-07-16 at 12 17 03
ecmel commented 1 month ago

@flapili While searching for a solution I bumped into https://stackoverflow.com/questions/42213316/how-to-share-file-in-android Not tried yet but can be a simple solution for file sharing.

ecmel commented 1 month ago

Also, the following capacitor plugins can be relevant:

https://github.com/ionic-team/capacitor-plugins/tree/main/share https://github.com/capacitor-community/file-opener