Reputation: 139
I use the same way it's mentioned in [Node][Angular] How to download excel files generated by node but still I don't get any popup to open or save. I could see the buffer in the Network window of Chrome.
Any help is appreciated.
Upvotes: 0
Views: 1011
Reputation: 1732
On the client side you can use:
$http({method: 'GET', url: '/someUrl'}).
success(function(data, status, headers, config) {
let blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
const fileName = `file.xlsx`;
let file = new File([blob], fileName);
let fileUrl = URL.createObjectURL(file);
})
.error(function(data, status, headers, config){
});
I used File because it allows you to pass filename. You could skip this part and pass Blob to URL.createObjectURL
. It opens window with download. Assuming your server code is correct. But if you see buffer in Chrome than it sends something.
For server side I usually use express res.sendFile
. It needs you to create a file so you gave to clean up.
Upvotes: 1