Is there a way for me to save an Excel file with its original filename from a service in my Angular
app using the file-saver
library? Below is my current code:
let blob = new Blob([response], {type: 'application/vnd.openxmlformat-officedocument.spreadsheetml.sheet;'});
saveAs(blob, 'hello.xlsx');
This is how the response looks like from the Angular service:
return this.http.get(`${this.reportsUrl}`, { responseType: 'blob'});
Here is the response from my backend service (Spring MVC). The excelCreateResource
is of type
org.springframework.core.io.Resource
:
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"))
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachment; filename=\"" + excelCreateResource.getFilename() + "\"")
.body(excelCreateResource);
I want to download the file with its original filename without specifying hello.xlsx
. When accessing the URL directly from the browser, I am able to download the Excel file successfully.