I have a Controller returning an "InputStreamResource file". I want that this file appears to the downloads. It isn´t important for me to return this file to the Frontend, but when it will be neccessary I can do this. How can I start a download? Thanks!
This is my Controller with the "InputStreamResource file":
@RequestMapping(path = "/csv", method = RequestMethod.GET)
public ResponseEntity<InputStreamResource> getCSV() {
String filename = "User.csv";
InputStreamResource file = new InputStreamResource(fileService.load());
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename)
.contentType(MediaType.parseMediaType("application/csv"))
.body(file);
}
Here I get the csv data in my frontend:
csv() {
this.userService.getCSV().subscribe(
{
next: data =>{
console.log(data)
}
}
);
}
output:
1,user1
2,user2
3,user3