[英]Angular 7 get corrupted file while downloading blob
Using Angular 7, i am calling api by posting the url file and try to download it by using 'saveAs' function from the fileSaver library. 文件正在下載,但無法打開,因為它已損壞。
我的電話如下:
var file_url = (response as any).headers['Location'] + 'files/Data.xlsx';
var filename = 'Data_' + this.getDateService.getDateFile() + '.xlsx';
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/x-www-form-urlencoded'
}),
responseType: 'arraybuffer',
observe: 'response'
};
let downloadParameters = { filename: 'Data_' + this.getDateService.getDateFile() + '.xlsx', file: file_url }
this.downloadFileService.downloadFile(downloadParameters, httpOptions).subscribe(reponse => {
var blob = new Blob([(response as any).body], { type: 'application/vnd.openxmlformat-officedocument.spreadsheetml.sheet' });
saveAs(blob, filename);
})
我嘗試了什么:
下面,來自服務的響應標頭:
該文件存在於響應正文中:
你們有什么線索嗎?
試試這樣:
this.downloadFileService.downloadFile(downloadParameters, { responseType: 'blob' }).subscribe(blob=> {
saveAs(blob, filename);
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.