I am using res.download() and the file is getting downloaded as well.But the pdf which is uploaded on the server and which I am getting with res.download is different i.e the one which I am getting downloaded is blank pdf.ALso a 200 response is returned in my server i.e that the file is present. Below is my code: Controller:
$http.get('/api/knowledges').success(function(data){
console.log("this is your data");
console.log(data);
$scope.knowledge=data;
});
$scope.download=function(fileDownload){
function downloadFile(filePath){
console.log("download funcion invoked");
console.log(filePath);
var link=document.createElement('a');
link.href = filePath;
//link.download = "my.pdf"
link.click();
}
downloadFile('/api/knowledges/file_download/?filepath='+fileDownload.file_details.path);
}
API:
exports.download = function(req, res) {
var filename='BookWorm Study Material.pdf';
res.setHeader('Content-type', 'application/pdf');
res.download(req.query.filepath,filename);
};
via Akshay
No comments:
Post a Comment