downLoad(msg) {
const url1 = `url`;
this.getBlob(`${url1}`).subscribe(result => {
this.downFile(result, 'name.zip');
})
}
**//post方法**
requestBlob(url: any, data?: any): Observable<any> {
return this.http.request("post", url, { body: data, observe: 'response', responseType: 'blob' });
}
**//get方法**
getBlob(url: any, data?: any): Observable<any> {
return this.http.request("get", url, { body: data, observe: 'response', responseType: 'blob' });
}
**// Blob文件转换下载**
downFile(result, fileName, fileType?) {
const data = result.body;
const blob = new Blob([data], { type: fileType || data.type });
const objectUrl = URL.createObjectURL(blob);
const a = document.createElement('a');
a.setAttribute('style', 'display:none');
a.setAttribute('href', objectUrl);
a.setAttribute('download', fileName);
a.click();
URL.revokeObjectURL(objectUrl);
}
Blob文件流下载
最新推荐文章于 2024-09-26 16:21:42 发布