Angular 4 new HttpClient content-disposition header

Viewed 22717

I am trying to get a file (array buffer) from my backend using the new HttpClient.

My code is pretty much like the following:

this.http.post(url, body, {responseType: 'blob', observe: 'response'})
  .subscribe(resp => {
    console.log(resp.headers.get('content-disposition'));
  });

The repsonse in my browser console is null

When I take a look at the network tab, then I see that content-disposition has a value like attachment; filename="whatever"

If I try to get content-type instead, then I receive something.

Have you experienced something similar or can you tell me what I have to do else? Many thanks

2 Answers

if your backend is using SpringSecurity you need add ExposeHeader to configuration source:

@Bean
protected CorsConfigurationSource corsConfigurationSource() {
    CorsConfiguration configuration = new CorsConfiguration();
    configuration.addExposedHeader("Content-Disposition");
    return source;
}
Related