how do i trigger a download in angular 2 when the backend is already providing the download in the response?
my backend provides an API endpoint like this:
Workbook userExcelReport = excelReportGenerator.createUserExcelReport(userSurveys);
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setHeader("Content-Disposition", "attachment; filename=\"" + userFileName + ".xlsx\"");
try {
userExcelReport.write(response.getOutputStream());
userExcelReport.close();
response.flushBuffer();
return new ResponseEntity(HttpStatus.OK);
} catch (IOException e) {
logger.error("The excel workbook could not write to the outputStream ", e);
return new ResponseEntity(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
that method is proved to work, (as entering the backend (with no frontend) triggers the download correctly) but now i want to make an angular 2 page that triggers the download
i have the page somewhat ready, i have this in the service:
return this._http.get(this.url, {
search: params
});
but now i dont know how to trigger the download with the response (dont know how should i map it or what)