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.

Kevin Garnick
  • 94
  • 1
  • 9
Sumit Sarkar
  • 169
  • 1
  • 2
  • 11

1 Answers1

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.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
  • Is there any API to do it? – Sumit Sarkar Oct 22 '17 at 16:44
  • @SumitSarkar: No, the path of the file that was selected is not made available by the browser *at all*. – T.J. Crowder Oct 22 '17 at 16:46
  • @T.J.Crowder Note, there is a bug at Firefox 47 where the full path is provided at `drop` event when `drop` occurs at ` – guest271314 Oct 22 '17 at 16:47
  • @T.J. Crowder thanks for your response, but there is some API called electron, which let you know the path of selected folder. – Sumit Sarkar Oct 22 '17 at 16:49
  • @SumitSarkar: [Electron](https://electron.atom.io/) 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. – T.J. Crowder Oct 22 '17 at 16:51
  • Thanks @T.J. Crowder – Sumit Sarkar Oct 22 '17 at 16:54