23

I searched quite a lot for an answer on the web and found nothing.

Is there a way to get the download path of a browser via Javascript?

I don't want to set the path myself i just wanna know where my file goes after been downloaded by the user.

Bolza
  • 1,904
  • 2
  • 17
  • 42

4 Answers4

32

That is not possible.

Pure browser-JavaScript is not be able to get information about the user's filesystem. The default download path might also contain sensible information, which is risky:

Imagine that one stores his downloads at C:\CompanyName\RealName\PhoneNumber\Adress\.

Rob W
  • 341,306
  • 83
  • 791
  • 678
  • 1
    `C:\Windows\Users\Username\Downloads` would be bad enough. – Quentin Mar 23 '12 at 14:40
  • 2
    So correct me if i'm wrong: i cannot programmatically access any file system folder from the browser. Any filesystem related action (read or save a file) can only be done by the user using or drag and drop interfaces. That's right? – Bolza Mar 23 '12 at 14:59
  • 1
    @SteNonesiste That is correct. There is no cross-browser solution for performing true filesystem-related actions. – Rob W Mar 23 '12 at 15:07
12

Browsers are deliberately isolated from the local filesystem in order to prevent scripting attacks. You cannot get this information.

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176
2

https://www.npmjs.com/package/downloads-folder

Usage

const downloadsFolder = require('downloads-folder');

console.log(downloadsFolder());

Installation

$ npm install downloads-folder
Seth Eden
  • 1,142
  • 2
  • 20
  • 42
  • I don't understand this answer. the npm module uses `execSync` which is a C extension for Node. Isn't it for the server side? – Kenji Noguchi Jan 16 '18 at 22:04
  • 1
    I use it for TestCafe which is typically client-side test script execution. Works great on Windows Chrome, but I'm sure I'll have to make adjustments when I start running it against Mac, and perhaps some adjustments for other browsers too, as that seems the be the general trend across most feature-functions. npm itself just installs it on the server so you'll have the necessary libraries on your machine when you execute the code. – Seth Eden Jan 18 '18 at 12:16
  • 1
    @SethEden I can confirm this works on mac as well. And my exact use case is also testcafe :-) – hitautodestruct Sep 09 '19 at 08:50
  • are there no alternatives method other than adding an extra module? – Adépòjù Olúwáségun Jan 31 '20 at 15:58
  • I get this error: `Module not found: Can't resolve 'registry-js' in '.../node_modules/downloads-folder'` – Zedd May 10 '21 at 07:41
1

Maybe wrong answers. You can do it with some IE versions. It is valid in case you use it for intranet web development as development of products/workflow that requires files. It does not work with other browsers (Schrome, Firefox, Safari, AFAIK).

<input
type="hidden"
id="steel_that_path"
name="steel_that_path" />


<input type="file"
id="this one you use to upload file"
name="this one you use to upload file"                                              
accept="application/octet-stream"                                                 
onBlur="document.getElementById('steal_that_path').value=this.value;"/> 
Denis Tsoi
  • 9,428
  • 8
  • 37
  • 56
tom
  • 2,190
  • 1
  • 23
  • 27