i did try to download excel template file in angular6 using spring boot. in rest api file is getting download properly but when integrate rest api with angular excel file is not getting download. Please any one can help
From angular to api is calling very fine
servivce.ts file
download(data){
const REQUEST_PARAMS=new HttpParams().set('fileName',data.fileName);
const REQUEST_URI='/downloadTemplate';
// don't have any issue with url as eddit by me
return this.http.get(REQUEST_URI,{
params:REQUEST_PARAMS,
responseType:'arraybuffer'
})
}
component file
download(){
this.fileName='download.xlsx';
const EXT=this.fileName.substr(this.fileName.lastIndexOf('.')+1);
this.service.download({'fileName': this.fileName})
.subscribe(response=>{
saveAs(new Blob([response], {type:'application/vnc.openxmlformats- officedocumnet.spreadsheetxml.sheet'}), this.fileName);
})
}
You need to add
{ responseType: 'blob' }Try like this:
service.ts
component.ts