On a server I have several files which are protected via HTTP authentication.
Now I want to create download buttons on my HTML page to download these files. I already read that downloading a file via JavaScript/AJAX isn't possible due to security reasons. See this question.
Furthermore via an "normal" download link/button like this:
<a href="..." download>
You can try the username:password
syntax in the url:
<a href="username:password@example.com/file.zip">Download</a>
However, do note that browser manufacturers have started removing support for this for security reasons. IE and Chrome no longer support it.
As a work-around, you can make the request on your server instead of directly from the HTML in the browser. Just write a simple script that accept a request and fetches the password protected file.
Here's a simple node.js example using express
and request
:
var express = require('express');
var request = require('request');
var app = express();
app.get('remote-file',function(req,res){
request.get('username:password@example.com/file.zip').pipe(res);
});
app.listen(80);
Yes, the request module supports username:password
syntax.