在我的node / express app中,我有以下服务器端文件下载功能:
app.get('/download_playcards_export', function(req, res){
var file = fs.createReadStream('/Users/eugene/Documents/dev/node/DataManager/PlayCards.csv');
var stat = fs.statSync('/Users/eugene/Documents/dev/node/DataManager/PlayCards.csv');
res.setHeader('Content-Length', stat.size);
res.setHeader('Content-Type', 'text/csv');
res.setHeader('Content-Disposition', 'attachment; filename=PlayCards.csv');
file.pipe(res);
}
);
我可以在浏览器控制台上看到我的.csv文件的内容:
$scope.exportPlaycardsData = function(){
$http.get('/download_playcards_export').success(function(response) {
console.log('success downloading playcards export ' + response);
});
}
但我无法让浏览器只下载此文件。
我该怎么做才能解决这个问题?