I am trying to stream a csv
file from a node.js server. The server portion is very simple :
server.get('/orders' function(req, res) {
res.setHeader('content-type', 'text/csv');
res.setHeader('content-disposition', 'attachment; filename='orders.csv');
return orders.pipe(res); // assuming orders is a csv file readable stream (doesn't have to be a stream, can be a normal response)
}
In my angular controller I am trying to do something like this
$scope.csv = function() {
$http({method: 'GET', url: '/orders'});
};
This function is called when there's a click on a button with ng-click
in my view :
<button ng-click="csv()">.csv</button>
I have looked at other answers about downloading files from server in Angular, but didn't find anything that worked for me. Is there a common way to do this ? Seems like something that should be simple.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…