I am using file saver on Angular 7 to save CSV file returned from Spring Boot backend. Spring Boot returns CSV File object with some properties i.e name, size, type, and file content in a byte array format. When I open save page, File Saver saving file with byte array text instead of converting to CSV format and saving it to the file.
getFileContent
getFileContent(id)
{
this.filesService.getFileContent(SERVER_API_URL + "files/" + id).subscribe(
data =>
{
this.fileObservable = data;
let blob = new Blob([this.fileObservable.fileContent], {type: "text/csv;charset=utf-8"});
saveAs(blob, "test.csv",{ autoBOM: true });
});
}
Rest API:
@GetMapping(value = "/files/{id}")
public CsvFile getFileById(@PathVariable Long id)
{
return csvUploadService.getFileById(id);
}