To implement the new Angular Http, you can follow the code snippet below in your Service.
downloadFile(): Observable<HttpResponse<Blob>> {
return this.http.get<Blob>(this.someURL, {
observe: 'response',
responseType: 'blob' as 'json'
});
}
Then, you can utilize the above function like this
this.someService
.downloadFile()
.subscribe(
(response: HttpResponse<Blob>) => {
console.log(response.headers.get('content-disposition'));
data = response.body
});
Additionally, on the backend, it is important to include the following header in the response object:
'Access-Control-Expose-Headers': 'Content-Disposition'
Similarly, in Java Spring Boot, you can achieve the same functionality by using the code below
final HttpHeaders headers = new HttpHeaders();
headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=1.xlsx");
headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);