nbro
nbro

Reputation: 15837

How to obtain the browser's download location using Node JS?

I need to transfer files from one location to another, and the destination folder should be the user's download location.

I was wondering if it's possible to obtain the browser's download location using Node JS or simply Javascript. I need a way to do it that works for all systems and browsers possibly.

Up to now I was just typing the location manually, but I need an automatised way of doing it of course!

Upvotes: 2

Views: 7276

Answers (2)

jfriend00
jfriend00

Reputation: 707178

It is not possible in node.js to know the user's download location unless you ask the user to specifically type it into some input field in a form. That location is purely a user agent setting that is purposely not disclosed to any server or web page for security reasons.

Furthermore, the server or webpage cannot influence where a file might be saved by the browser on the user's local hard drive anyway (again for security reasons) so there's nothing useful a server can do with that information anyway unless you happen to be running a server that is on the same machine as the browser. If you're working in that type of controlled environment, then perhaps you could use a browser extension that does have access to some of these kinds of things.

Upvotes: 2

Dave MacDonald
Dave MacDonald

Reputation: 101

At least on Windows, this will normally be %USERPROFILE%/Downloads.

In NodeJS, you could write: var downloadFolder = process.env.USERPROFILE + "/Downloads";

Upvotes: 3

Related Questions