How can I read a file from disk by FileDialog on WASM

For example

if ui.button("Open").clicked() {

    // Open a FileDialog and pick a file.
    // Then read the data from disk.

You can use rfd - Rust.

It looks like you're using egui, there is an example here.

1 Like

Thanks, it works perfectly on my laptop, but when I switch target_arch to wasm32, due to the inactivate FileDiaglog code, it does not work.

There are only a AsyncFileDialog in rfd when #[cfg(traget="wasm32")], I have tried like this:

if ui.button("Open").clicked() {
    let future = async {
        let file = rfd::AsyncFileDialog::new().pick_file().await;
    let data = async_std::task::block_on(future);

Thanks again, it worked.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.