我正在尝试下载excel文件,从angular js的按钮上点击POST
调用。我的java控制器返回void。
要写入excel文件的服务:
response.setContentType("application/ms-excel");
response.setHeader("Content-Disposition","attachment filename=\"" + fileName + ".xls"+ "\"");
workbook.write(response.getOutputStream());
响应的类型为HttpServletResponse
。
如何在Angular
中编写下载文件的方法??
发布于 2019-01-29 15:29:28
从服务器下载文件。
单击按钮时调用函数。
downloadFile():void
{
this.getFiles("http://localhost:80080/api/demo/GetTestFile")
.subscribe(fileData =>
{
let b:any = new Blob([fileData], { type: 'application/zip' });
var url= window.URL.createObjectURL(b);
window.open(url);
}
);
}
public getFiles(path: string):Observable<any>{
let requestOption = new RequestOptions({responseType: ResponseContentType.Blob});
return this.http.get(filePath, requestOption)
.map((response: Response) => <Blob>response.blob()) ;
}
https://stackoverflow.com/questions/54415810
复制相似问题