Native file picker APIs do not return native path of the local file
ssnangua opened this issue · 1 comments
Issue Type
- Feature Request
Current/Missing Behavior
The native web API showOpenFilePicker()
, showSaveFilePicker()
and showDirectoryPicker()
do not return native path of the local file.
Expected/Proposed Behavior
The returned FileSystemFileHandle
object or FileSystemDirectoryHandle
object contain native path of the local file, such as path
.
Additional Info
Compared to creating an <input type="file">
, this is a more convenient way to show a file picker.
In addition, support for setting MIME type groups is also very useful.
- Code snippet:
window
.showOpenFilePicker({
types: [
{ description: "JPEG", accept: { "image/jpeg": [".jpeg", ".jpg"] } },
{ description: "PNG", accept: { "image/png": [".png"] } },
{ description: "GIF", accept: { "image/gif": [".gif"] } },
],
excludeAcceptAllOption: true,
multiple: false,
})
.then(([fileHandle]) => {
console.log(fileHandle);
});
For historical reasons, the value IDL attribute prefixes the filename with the string "C:\fakepath". Some legacy user agents actually included the full path (which was a security vulnerability). As a result of this, obtaining the filename from the value IDL attribute in a backwards-compatible way is non-trivial.
https://html.spec.whatwg.org/multipage/input.html#fakepath-srsly
This is probably why FileSystemHandle and similar APIs don't provide the native path.