Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native file picker APIs do not return native path of the local file #8178

Open
1 task done
ssnangua opened this issue Apr 11, 2024 · 1 comment
Open
1 task done

Comments

@ssnangua
Copy link

ssnangua commented Apr 11, 2024

Issue Type

  • Feature Request

Current/Missing Behavior

The native web API showOpenFilePicker(), showSaveFilePicker() and showDirectoryPicker() do not return native path of the local file.

image

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.

image

  • 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);
  });
@ssnangua ssnangua changed the title Native file picker API do not return native path of the local file Native file picker APIs do not return native path of the local file Apr 11, 2024
@ayushmanchhabra
Copy link
Contributor

ayushmanchhabra commented Apr 20, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants