0

I have a function that downloads the file from server.

private _downloadFromUrl(url: string, fileName = "download.bin"): Observable<any> {
    const _response$ = new Subject<any>();

    this.http.get<Blob>(url, {
        observe: "response",
        responseType: "blob" as "json"
    })
        .subscribe(
            (response: any) => {
                console.log(" response.headers", response.headers);
                saveAs(response, fileName);
                _response$.next(true);
                _response$.complete();
            },
            (err) => {
                _response$.error(err);
                _response$.complete();
            }
        );
    return _response$;
}

I am unable to read all the response headers. I want to read file name.

this is what i get in response.headers.keys()

["cache-control", "content-length", "content-type", "expires", "pragma"] 

but in browser these headers are present

ACCESS_CONTROL_EXPOSE_HEADERS: CONTENT_DISPOSITION 
CONTENT_DISPOSITION: abc.xml 
x-filename: abc.xml

is present in my response headers.

but if i try response.headers.get("CONTENT_DISPOSITION") or response.headers.get("x-filename") or response.headers.get("CONTENT-DISPOSITION") it returns null

Sunil Garg
  • 14,608
  • 25
  • 132
  • 189

0 Answers0