directory uploads should be easier
I've been working on a website called Cassettes
: a music player with a twist (I'll pop a link here when I release it).
At its core it reads and plays the user's local music collection.
All the user has to do is point the site at their music folder and they're off to the races.
There's one problem with this though: it's impossible.
There are three methods to get access to a directory from a website.
The first is to use an <input type=file>
.
On its own this only allows selecting a single file, but when combined with the experimental webkitdirectory attribute (and possibly the multiple attribute), directories become available for selection.
A slight hurdle is the fact that it flattens all the files in the directory and subdirectories into a single list, though thankfully with the file path stored in the webkitRelativePath
property.
A bigger hurdle is browser compatibility, where all major browsers except Firefox mobile are marked as supported.
Upon brief testing, no mobile browsers were found to work.
So the native file picker doesn't work, but hope is not lost!
The Drag and Drop API allows us to define dropzones into which we can drag files from a file manager.
Even better, it supports directories out of the box and browser compatibility is green across the board (as long as Opera isn't on the board).
The catch?
Dragging files around on mobile is infeasible so this method also does not work.
The gods have not forsaken us yet, though!
The beautiful people over at the Web Incubator Community Group have been incubating the File System Access API for 8 years (insert awed expletive here).
This API is focused on expanding the file-writing and directory-managing abilities of the browser, and is exactly what I was looking for.
The bad news is that the Firefox team consider it harmful and refuse to help get it on standards track.
The result: not supported in Firefox or mobile browsers.
So that's a bummer.
But what can we do about it?
I'd suggest getting involved in the standards process.
Until the Firefox team is satisfied (or convinced) that the potential evil of letting websites read or edit user files (with permission) is lesser than that of native apps doing whatever they want, we will be stuck in a world without directory uploads.
These thoughts were originally a Mastodon post.
If you know something I don't, or have any suggestions, please do reply there.