tauri-apps / tauri

Build smaller, faster, and more secure desktop applications with a web frontend.
https://tauri.app
Apache License 2.0
81.82k stars 2.45k forks source link

[feat] FileDialog for mobile #6517

Open Berrysoft opened 1 year ago

Berrysoft commented 1 year ago

Describe the problem

I would like a FileDialog for mobile platforms.

Describe the solution you'd like

Any solution which allow me to read the files is OK.

Alternatives considered

No response

Additional context

No response

FabianLars commented 1 year ago

Upstream issue: https://github.com/PolyMeilex/rfd/issues/82 - i don't know how feasible implementing this in rfd would be though.

Berrysoft commented 1 year ago

As far as I know, Android Indent should be enough to pick files, though it is a bit complicated to use.

In addition, iOS UIDocumentBrowserViewController cannot get paths of picked files. Instead, it returns array of NSURL, and you get the content of the files with [NSData dataWithContentsOfURL:] or [NSInputStream inputStreamWithURL:]. It is different from the dialog API of tauri and rfd now.

PolyMeilex commented 1 year ago

In addition, iOS UIDocumentBrowserViewController cannot get paths of picked files. Instead, it returns array of NSURL, and you get the content of the files with [NSData dataWithContentsOfURL:] or [NSInputStream inputStreamWithURL:]. It is different from the dialog API of tauri and rfd now.

RFD already has to handle this because web does not have paths either, that's why async file dialogs return FileHandle new type, instead of a path (could do the same for sync ones, but those are not supported on the web so there was no reason to do it so far), it is unwrappable on platforms that support paths tho. So I think it should be doable.

Berrysoft commented 1 year ago

I've tried for both mobile platforms.

iOS: https://github.com/Berrysoft/file-picker-ios , which reads the file content and passes the Arc<[u8]> as FileHandle. It is a simple library and could be used anywhere.

Android: https://github.com/Berrysoft/file-picker-android , which copies the file to a reachable path and passes the PathBuf. It is a Tauri plugin.

I don't have much time to investigate how to integrate them into Tauri. Maybe there are someone would like to take my code as reference.