Get browser download path with javascript
Solution 1
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\
.
Solution 2
Browsers are deliberately isolated from the local filesystem in order to prevent scripting attacks. You cannot get this information.
Solution 3
https://www.npmjs.com/package/downloads-folder
Usage
const downloadsFolder = require('downloads-folder');
console.log(downloadsFolder());
Installation
$ npm install downloads-folder
Solution 4
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;"/>
Bolza
Updated on April 17, 2020Comments
-
Bolza about 4 years
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.
-
Quentin about 12 years
C:\Windows\Users\Username\Downloads
would be bad enough. -
Bolza about 12 yearsSo 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 <input> or drag and drop interfaces. That's right?
-
Rob W about 12 years@SteNonesiste That is correct. There is no cross-browser solution for performing true filesystem-related actions.
-
Kenji Noguchi over 6 yearsI don't understand this answer. the npm module uses
execSync
which is a C extension for Node. Isn't it for the server side? -
Seth Eden over 6 yearsI 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.
-
hitautodestruct over 4 years@SethEden I can confirm this works on mac as well. And my exact use case is also testcafe :-)
-
Adépòjù Olúwáségun over 4 yearsare there no alternatives method other than adding an extra module?
-
Zedd almost 3 yearsI get this error:
Module not found: Can't resolve 'registry-js' in '.../node_modules/downloads-folder'