1

I want to get the path of selected folder. Here is my code:

<input style="display:none;" id="fileDialog" type="file" webkitdirectory />

var chooser = document.querySelector('#fileDialog');
    chooser.addEventListener("change", function(evt) {
      console.log(this.value);
    }, false);
    chooser.click(); 

Using this code i'm getting a fakepath.

Is there anyway in node.js,so i can get the path of my selected folder. I'm using express framework in node.js.

2
  • You're talking about the path of the file on the client machine, right? Commented Oct 22, 2017 at 16:47
  • 1
    path of a folder that i selected from window dialog Commented Oct 22, 2017 at 16:51

1 Answer 1

1

There's no way for you to get the path of the file selected in an input type="file" at all, full stop. Not on the browser, and not transmitted to the server for you to use in Node/Express. That information is simply not available to you. Browsers let you know the name of the file, but that's it.

Sign up to request clarification or add additional context in comments.

6 Comments

Is there any API to do it?
@SumitSarkar: No, the path of the file that was selected is not made available by the browser at all.
@T.J.Crowder Note, there is a bug at Firefox 47 where the full path is provided at drop event when drop occurs at <textarea> element, see How FileReader.readAsText in HTML5 File API works?
@T.J. Crowder thanks for your response, but there is some API called electron, which let you know the path of selected folder.
@SumitSarkar: Electron isn't an API, it's a framework for building desktop applications with web technologies. I said the browser doesn't make this information available; and it doesn't. Electron apps use web technologies, but they are not browsers.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.