html - Download file from url angular 2 -


i have url : http://localhost:9999/file/bongda.png

i using nodejs serve public file :

application.use(express.static(path.join(__dirname, 'uploads'))); 

and

application.get('/file/:name', function (req, res, next) {    var options = {     root: __dirname + '/uploads/',     dotfiles: 'deny',       headers: {         'x-timestamp': date.now(),         'x-sent': true     }   };     console.log('express server listening downloads ');   var filename = req.params.name;   res.type('png');    res.sendfile(filename, options, function (err) {     if (err) {       next(err);     } else {       console.log('sent:', filename);     }   });  }); 

i want download file url

i using <a href="window.location.href='http://localhost:9999/file/bongda.png'">123123</a> or

<a href="http://localhost:9999/file/bongda.png">123123</a> 

but not success . please me ?

you've missed javascript: href:

<a href="javascript:window.location.href='http://localhost:9999/file/bongda.png'">123123</a> 

if you'd force browser download file instead of opening it, following line should added backend code:

res.setheader('content-disposition', 'attachment; filename=' + filename); 

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -