Download file without opening download dialog - javascript

The Problem:
I need to force the download dialog not to open in a browser when in a downloading process:
I have the server code like any other download servlet.
On the client side I have a link that points to the servlet like any other download link.
Is there a way to download automatically when clicking on the link without opening the dialog?
What I think is that it may be related to the following:
Server code (Java) ?
Client code (JavaScript) ?
Browser settings ?
Browser type ?
The Purpose behind this:
There is a website that belongs to this company where it is fortified with a high security wall clearing out the chance of downloading any virus.
The clients of this site need to have the download link saving automatically when clicked on.

No, you can't interact with files on HDD from a browser without notifying the user. It's a security policy.

If I understand well, you want the browser to download your file on a default folder without asking you where?
Well, I think that, this depends on your browser, maybe you can customize the configuration in order to set a default download folder, but, I think it is not possible to force it on the server side.

Related

Download and open a file by javascript

I am making a SPA.
I want to download a file (e.g. .xlsx) and open a "Open With" dialog like this, by javascript.
Or open the file on client's PC.
Is there a way to solve this?
I know javascript cannot access to local files without
<input type="file">.
I want any advice. (even THIS IS IMPOSSIBLE)
I'm assuming your SPA has an API? Well, you need to the direct the user to an API endpoint that will create and then send to the client the .xlsx file.
You can use the Content-Disposition header to control how the browser will open the file.
Kind regards,

Javascript trigger download outside of browser

What would be the best way of triggering a download outside of the browser?
I have a Html Page which is not on a Server but should only function as a Digital Signage Viewer. The Server (which already exists) sends a playlist over TCP Sockets (the server is a bit older) telling the client what media it needs to download from where and where the media is supposed to be presented.
The communication between the Javascript Client code and the Tomcat server is irrelevant for now. What I would like to know is if there is a way to download the files to a certain directory without letting the browser download the file (Problems -> Download Pop Up -> Confirmation -> Can't preset different download folders etc. with Javascript), so that I can set the source of the media tags after they have downloaded ?
(If you're asking why I'm not simply streaming the media it's because if the connection is lost the media still needs to continue to play)
I really hope my explanation makes any sense.
Cheers
Cris
You may send the content to a web server and return it back to browser with specified type/filename. For example in PHP you may do something like this:
header('Content-type: text/html');
header('Content-disposition: attachment;filename=myfile.txt');
Another option is this nice JavaaScript library which allows you to save some contents on client-side:
https://github.com/koffsyrup/FileSaver.js
It allows you to do something like this in browser:
saveTextAs("Hi,This,is,a,CSV,File", "test.csv");
You may also want to store your contents in browser's localStorage or sessionStorage.
What I would like to know is if there is a way to download the files to a certain directory without letting the browser download the file
If this would be possible it would open a security leak because it would make it possible to put special files (like programs) into special folders (like autostart) and then cause unwanted execution of code. This this is hopefully not possible due to security concerns.

How to download a file using javascript?

Hi is there any chance to download a file into local system without displaying downloading process at the front end ?
I am trying as below
var f = document.createElement("iframe");
f.setAttribute("id", "theFrame");
document.body.appendChild(f);
document.getElementById("theFrame").location = 'http://www.example.com/yourfile.doc';
I am able to download the file but it was displaying in the front end of the browser as the file is getting download.
No. That is not possible.
A web site is by definition untrusted. And you don't want to let untrusted web sites make changes to your system, even if it is 'just' a file download (which could be potentially dangerous since it can contain a virus for example).
Therefore a browser will show the download to the user as it thinks it is appropriate. Nothing you can do about that.
(As you have built already, you can download it without permission, you just can't hide the download)
Not possible. When the browser detects a file download it will show up in the download bar and you can't (at least you shouldn't be able to) stop this - it's the way the browser works and has nothing to do with javascript/php code.
I also can't think of any use case where you would want to hide this from your user, except for malicious intent (like a virus).

add print and download protected pdf viewer to web site

Is there any way to add slide share like PDF viewer to the web site?
Only users can be able to view document... print or download can't be done.I tried several JavaScript plugins for doing that but unable to find one that has no print and downloadable options. And also client can disable JavaScript in browser therefore I think of that suitable server side script.
I also unable to find a server side script (PHP) for this. Please suggest.
Just keep the file outside the web root directory because the web browser follows the local file system privileges and not its own. Put them into a directory with a .htaccess file that blocks all communication.
Ex: Order deny,allow
deny from all
I don't know how much it will gonna help you.

Force ask where save file before download

I have an embedded system with a web server Mongoose, I have to allow the client to download some log files generated at runtime, I have a problem during the download, in practice, the browser first downloads the file and then asks where to save the file .
The behavior is unpleasant because the download takes a few seconds and the client does not understand what's going on.
Is there any option, for example, in the header of the file, to force the browser to ask before making the download where to save the file?
Thanks.
it is not up to you to decide how the client's browser is behaving.
if the browser is set to save the file automatically in a specific place, then there is nothing you can do.
your only workarounds is to either upload your file somewhere and suggest the viewer to right-click a download link that points to the file, it will open the dialog,
or suggest the viewer to change browser settings,
or write a browser extension that does that and offer viewers to install it.

Categories

Resources