DioxusLabs / dioxus

Fullstack app framework for web, desktop, mobile, and more.
https://dioxuslabs.com
Apache License 2.0
21.34k stars 821 forks source link

File input directory type does not keep directory structure for files() and subsequently drops duplicates #3136

Open rogusdev opened 3 days ago

rogusdev commented 3 days ago

Problem

Using a directory / webkitdirectory file input to upload a directory, and then looping over the files() results, 2 things are broken:

  1. there is no folder structure with the filenames to identify where they came from per https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory#understanding_the_results
  2. because of 1, if there is a duplicate filename in another directory, the names collide and only one remains

Steps To Reproduce

                        input {
                            type: "file",
                            multiple: true,
                            directory: true,
                            onchange: move |evt| {
    if let Some(file_engine) = evt.files() {
        for filename in file_engine.files() {
            log::warn!("filename {filename}");
        }
    }
                            },
                        }

Expected behavior

If you upload a folder "a", with structure like:

a/1.txt
a/o.txt
a/b/1.txt
a/b/2.txt

You will only see:

1.txt
o.txt
2.txt

Which has lost the second 1.txt, because it also lost the subdir "b" from the file paths.

Instead I would like to see:

a/1.txt
a/o.txt
a/b/1.txt
a/b/2.txt

Note that the initial "a/" is required, because a folder was uploaded, not simply files inside that folder!

Environment:

Questionnaire

I'm interested in fixing this myself but don't know where to start

rogusdev commented 1 day ago

Related to https://github.com/DioxusLabs/dioxus/issues/3134

And I am looking into how I can implement this in Dioxus.