shmnsw
shmnsw

Reputation: 649

Download a file using jquery redirect to the page instead of downloading

As i saw in some threads, i may download a file that way:

$('.download').click(function(){
     window.location.href = 'images/apple_juice.jpeg';
});

But instead i am getting a page presenting this image.

Upvotes: 0

Views: 195

Answers (1)

shmnsw
shmnsw

Reputation: 649

For future reference, i have managed download using node.js:

backup.get('/download-backup-file&:file_name', function(req, res){

    var file_name = req.params.file_name.split('=')[1];
    var file = 'backups/'+file_name;
    res.download(file); // Set disposition and send it.

});

Upvotes: 1

Related Questions