res.download function is not working in express.js

Multi tool use
Multi tool use


res.download function is not working in express.js



I want to download a file in node.js using express.js framework according to the get request url.



I didn't get an error in this code, but the file is not downloaded, it shows
success message.



Kindly look at following code, can anyone solve this issue?




var express=require("express");
var bodyparser=require("body-parser");
var app=express();
var path=require("path");
app.get("/download/:folder/:file(*)",function(req,res)
{

var folder=req.params.folder;
var filename=req.params.file;
var downloadlocation=path.join(__dirname,folder,filename);
console.log(downloadlocation);
res.download(downloadlocation,function(err,success)
{
if(err)
{
console.log("download failed try again");
}
else {
console.log("download successfully");
}
});

});

app.listen(8086,function()
{
console.log("server is listening on port 8086");
});





res.download(downloadlocation, filename, function(err,success)
– Lawrence Cherone
Jul 1 at 17:24


res.download(downloadlocation, filename, function(err,success)





Are you sure that it is not downloaded. The given code works fine here.
– t.niese
Jul 1 at 17:24





@LawrenceCherone the signature is res.download(path [, filename] [, options] [, fn]) so filename is optional. And because of the downloadlocation=path.join(__dirname,folder,filename) it would not make any difference here.
– t.niese
Jul 1 at 17:25



res.download(path [, filename] [, options] [, fn])


filename


downloadlocation=path.join(__dirname,folder,filename)





It is not working here
– demo developers
Jul 1 at 17:41





Can you try hard code a file url path and test whether it works?
– Marcia Ong
Jul 1 at 17:56









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Lpc isReiADC9dy7GKPo gWeiBybbaiuBjtoAd,CnZZ Ao7nTf4Gk643GTgxfdKiG,EwJ OsNe
jA RRu0bx0 X1DesKi w17mI of,M lx,Pw9jtflLVzLeb3WefRBq8EoCTbJko9xbWSm8VR

Popular posts from this blog

Rothschild family

Cinema of Italy