You can simply make use of the Download attribute in HTML. Using good ol' Javascript, you can use this feature to download the file directly. The download attribute of the anchor tag should point to the link where the file to be downloaded is hosted.
Firstly, point the URL to your resource path:
var url = 'your url goes here';
Create an anchor tag, with the needed attributes as below:
var elem = document.createElement('a');
elem.href = url;
elem.download = url;
elem.id="downloadAnchor";
Append the anchor tag to the body element of the webpage.
document.body.appendChild(elem);
Now trigger the click event programmatically. Clicking on the anchor tag will trigger the download.
$('#downloadAnchor').click();
Putting it all together:
var url = 'your url goes here';
var elem = document.createElement('a');
elem.href = url;
elem.download = url;
elem.id="downloadAnchor";
document.body.appendChild(elem);
$('#downloadAnchor').click();
Additional Information: Nothing fancy in the above code, just client-side JavaScript which works from Chrome Devtools' Console, but powerful and also opens up a lot of possibilities like webpage crawling.
For e.g. the following chunk of code executed in the Devtools console will open all the links in the page in a new tab: Just goto this webpage , open devtools and run this script in the browser console and watch the power of JavaScript unfurl. (Note: The below code is purely for educational purposes only.)
Make sure you enable pop-ups for that site, else your anchor clicks will get disabled by the default pop-up blocker.
var links = document.getElementsByClassName("_3ATBKe");
for(var i=0;i<links.length;i++){
var title = document.getElementsByClassName("_3ATBKe")[i].firstElementChild.firstElementChild.innerText.replaceAll('|','-').replaceAll(':','x');
console.log('Opening..'+title);
links[i].firstElementChild.click();
}
Note: This is not just limited to anchor clicks, you can download almost anything you find on your webpage. If something (image, audio, video) loads on your webpage, you can probably write a script to download it, even if the provision is not provided to you from the UI.