file-selector: react-dropzone v8.2.0 returns only file name in path property in electron, not the path

The files Objects returned on onDrop used to return the entire file path in the path property. Sinse v8.2.0 not any more.

The path property should contain the entire path, just as it does in v8.1.0.

According to https://github.com/react-dropzone/react-dropzone/issues/769#issuecomment-466914018 the issue lies in file-selector.

Last tested with react-dropzone v10.0.4 that according to

$ yarn list --pattern file-selector
yarn list v1.13.0
└─ file-selector@0.1.11
Done in 3.56s.

contains file-selector v0.1.11

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 10
  • Comments: 39

Most upvoted comments

Any success in this , same issue I’m also receiving…

In case there is anyone looking for a way to get a full-path in an electron environment, I recommend to try setting getFilesFromEvent to useDropzone as mentioned below; https://github.com/electron/electron/issues/44600#issuecomment-2465774352 along with webUtils.getPathForFile API of electron. https://www.electronjs.org/docs/latest/api/web-utils#webutilsgetpathforfilefile

You might as well try to pass onDrop https://html.spec.whatwg.org/multipage/indices.html#ix-handler-ondrop directly to the DOM that you use getRootProps() on, not via useDropzone:

    const onDrop = (event: React.DragEvent<HTMLDivElement>) => {
      event.preventDefault();
      const file = event.dataTransfer?.files[0];
      if (file != null) {
         // use file here
      }
    };
      <div {...getRootProps()} onDrop={onDrop}>

because webUtils.getPathForFile(file) behaves as follows.

In the case where the File object passed in was constructed in JS and is not backed by a file on disk an empty string is returned. https://www.electronjs.org/docs/latest/api/web-utils#webutilsgetpathforfilefile

@barbalex ok. I may go ahead and close this and you can reopen when you encounter the issue again.

On Sat, Oct 5, 2024, 01:06 steveoh @.***> wrote:

This is by design for security. I suggest closing this.

— Reply to this email directly, view it on GitHub https://github.com/react-dropzone/file-selector/issues/10#issuecomment-2394729916, or unsubscribe https://github.com/notifications/unsubscribe-auth/AALJIOK5SMZKZGEHXBRHDV3ZZ4GOVAVCNFSM6AAAAABM7BIC6OVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJUG4ZDSOJRGY . You are receiving this because you were mentioned.Message ID: @.***>

@jmcrthrs please submit a proposal as a new issue and we’ll discuss there. Thanks.

I still observe this with react-dropzone 10.1.5 and file-selector 0.1.12. I had to pin react-dropzone at 8.1.0 to work around the issue.

Even though the source code npm pulled for file-selector appears to include the most recent commit that tries to address the issue, I can still set a breakpoint in minified code which writes over a path property containing the full path and replaces it with the filename only.

Yeah, you’re right. Unfortunately I have to deliver an app next week. Will revisit this issue after that.