Reputation: 707
i want to download file from folder to browser . my first code works fine .the file gets downloaded immediately but when i try to find the file specificly by id it does not works . dont know why ?
///client works
$.ajax({
type: 'GET' ,
url: '/download' ,
success : function()
{
window.open('/download?foo=bar&xxx=yyy');
}
});
/////server works
app.get('/download', function(req, res) {
res.download(__dirname + '/uploads/google.png');
});
////client not works
$.ajax({
type: 'GET' ,
url: '/download/' + id ,
success : function()
{
window.open('/download?foo=bar&xxx=yyy');
}
});
/////server not working
app.get('/download/:id', function(req, res) {
var id = req.params.id
console.log("ddddddddddddddddddddddddddddddddddddddddd")
console.log(id)
res.download(__dirname + '/uploads/google' + id +'.png');
});
Upvotes: 0
Views: 85
Reputation: 6017
Because you are passing values as query parameters and not URL parameter from client.
app.get('/download', function(req, res) {
var foo = req.query.foo;
var xxx = req.query.xxx;
console.log(foo)
console.log(xxx)
//res.download(__dirname + '/uploads/google' + id +'.png');
});
Upvotes: 1