Im trying to download a zip file to my local system by using API response to be of type zip using angular.but since it's of type zip i'm not able to accept that rather running into error.
a.service.ts
download() {
const headers: HttpHeaders = new HttpHeaders({
"content-type": "application/json",
"Accept": "application/zip"
});
return this.http.get(url, {headers: headers, responseType: "arraybuffer"});
}
a.component.ts
getDownload() {
console.log("Hello world");
this.Service.download().subscribe((responseData: any) => {
console.log(responseData);
},(error: any) => {
});
Tried by adding responseType to be "blob","text" and "arraybuffer"...nothing seems to be working
You need to remove the headers from your request and set responseType to blob
If you specify these headers, this will overwrite the default parsing from the blob
response type and try to parse the zip file as json data