I am unable to find, how to read filename from content disposition in angular 2 documentation. Can someone guide read the headers from server in angular 2content headers
With new Angular Http, one can try the following in the Service code.
downloadLink(): Observable<HttpResponse<Blob>> { return this.http.get<Blob>(this.someURL, { observe: 'response', responseType: 'blob' as 'json' }); }
And use the above as
this.someService .downloadLink() .subscribe( (resp: HttpResponse<Blob>) => { console.log(resp.headers.get('content-disposition')); data = resp.body });
Also, on the server side, one needs to set the following header in response. 'Access-Control-Expose-Headers': 'Content-Disposition'
Like in Java Spring Boot one can do the same using
final HttpHeaders headers = new HttpHeaders(); headers.add(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=1.xlsx"); headers.add(HttpHeaders.ACCESS_CONTROL_EXPOSE_HEADERS, HttpHeaders.CONTENT_DISPOSITION);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With