0
I have a code that makes a request my api in Node that returns me a csv file, but when I download the file, it comes only with null content
generateReport() {
this.layoutService.loading(this.buttons.report, true);
this.reportService.generateReport(this.purchases).subscribe(
(file) => {
this.layoutService.loading(this.buttons.report, false);
var newBlob = new Blob([file], { type: "text/csv" });
console.log(file)
const data = window.URL.createObjectURL(newBlob);
var link = document.createElement('a');
link.href = data;
link.download = "relatório-adimplência.csv";
link.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
},
(err) => {
this.layoutService.loading(this.buttons.report, false);
console.log(err)
this.layoutService.error(err.error)
}
)
}
What if you, instead of trying to create a Blob, create a urlencoded link with CSV? See the second solution of this link: https://stackoverflow.com/questions/3665115/how-to-create-a-file-in-memory-for-user-to-download-but-notthrough-server
– Isaac Bruno