I am trying to trigger a download when the user clicks on a link.
The files hosted on servers I do not own/have no control over so I can't just add direct URLs to files (for example: https://example.com/video.mp4). I have tried the following code but it does not do what I want it to do.
<a href="https://example.com/filedownload?file=video" download>Download</a>
I expect the code to download the file when the user clicks the link. But when the user clicks the link, it opens a new tab at the URL instead of downloading the file.
Also, the link is not a MediaFire style download. If you press CTRL+S when on the page you get linked to it downloads video.mp4.
There are three ways to trigger saving a URL to disk instead of following the default behaviour for the browser.
The download attribute only works for same origin URLs.
A Content-Disposition header which requires you control the server hosting the file.
Lying about the content type, ditto, and which is a terrible approach anyway.
The only way to achieve what you want would be to serve the file from a server you do control.
Related
I have a url that when entered in to the browser generates a XML file and automatically downloads it to the computer.
Is there a way of doing this inside node.js?
I have tried various fetch ideas but they just download the originating page and not the file that is generated.
UPDATE FOR CLARITY: The page I'm getting the file from is doing a <FORM METHOD="POST" ACTION="catalogDownload.asp?a=a"> When I hit submit (or use the URL with the search parameters) it will download a file called stuff.XML to the computer. It is the file stuff.XML that I would like to capture programmatically, ideally (but not essentially) in node.js. My main goal at the moment is to download the file without manual intervention.
Consider the following case:
In my webpage, I have two links that are used for downloading two distinct files, one for a.css and one for a.js.
CLIENT_AAA prefers to download the a.css file into /path/to/css/ folder and a.js file to /path/to/js/ folder in his specific computer. CLIENT_BBB will probably use different folders, but it's out of our scope.
Problem is that when this user saves a.js and then downloads a.css, the browser (Chromium in my case) suggests downloading the new file to /path/to/js/ folder because that was the last folder used for a download. User needs to click up, select css folder and then save the file.
I wonder if I can "suggest" the browser for a valid download folder for that user per link, so when user clicks <a href="a.css" download>a.css</a>, browser will open /path/to/css folder and when user clicks <a href="a.js" download>a.js</a>, it will open /path/to/js folder. Is that possible?
That's totally up to the browser. There's no HTTP header to do what you're asking. You can specify the filename in Content-Disposition but that's all.
Consider that if you could nudge the browser towards a particular path, and browsers followed your suggestion, that would let bad people create downloads that overwrite system files with whatever content they want. Of course, people can still do that to themselves, but letting the server direct the browser to a particular full path would be a severe security problem.
I am AJAX call and when the server (REST service) sends the response it is actually a link to the generated file something like
/project/tmporaryFiles/file.abc
(File extension is also customized) It is just a text file. when I use $window.open then it just opens the text file in the browser and displays the text. I would like to open a saveas dialog box so that user user should be able to save the file instead of viewing it in the browser. I have tried multiple threads of stackoverflow but could not found solution. Most of the solutions are for HTML5 i.e. the download attribute in anchor, I believe this is not available in HTML4x.
One solution I am trying to find is to create a Blob with the response link but that I am unable to do.
Also note the file can be more than 100MB as well based on the data processing and input by the user.
I you want to force the download without using HTML5 download attribute, you will need to set Content-Disposition on response header.
This can be done on server side and not client.
I am trying o make app for my work (will be used only in my office) and among other things I need way to download file (it will be always one ODT and one txt document which will be initiated by clicking on button by user, on specific page - standard download) from our local server. Those two files are created on server and then sent to download to user which requested it, so that part is simple as any other web page which offers you download.
But after download is finished I need somehow:
1) automatically open ODT (openOffice writer) file, so user can continue editing it. What will happen next is not important...
2) automatically move TXT file to specific folder on users disk (this is needed because that specific folder is monitored by our special printer and whenever printer detects file in that folder it automatically starts printing). Setting default chrome download folder as that monitored folder is not options - so I NEED to move TXT file automatically after download to that monitored folder.
3) After first two actions are finished I need to clean default download folder (foldere where chrome downloads by default) because it would be full of those files and they are not needed anymore.
Now, it would be great if I could accomplish it just with javascript but as I know there is no way to manipulate files on local system without displaying dialog to user - so this is not option.
I figure it out that this part could be done by chrome extension, which is acceptable solution because this application will be used only in my office. But I am not sure how and if it is really possible to accomplish what I want so I need your help.
P.S.
It is important that after user click "Download" on page to download ODT and TXT file, there is no other windows, dialog and other "questions" by browser but everything after that should go automatically.
Thank you!
Yes, you can do those tasks with chrome.downloads API, as long as you can accept a subfolder of the Downloads folder as a target for your printer. You cannot download in an arbitrary folder, I'm afraid.
After a download you initiated with chrome.downloads.download finishes, you can initiate opening it with chrome.downloads.open(downloadId).
You can initiate a download into a subfolder by supplying a relative path to chrome.downloads.download (note the / slash instead of \): printout/file.txt.
You can remember the download id's and clean up afterwards with chrome.downloads.removeFile(downloadId).
Please take note of the permissions you need to add, they are quite fine-grained for this API.
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.