我有一個下載檔案的 API,我在按鈕上有一個按鈕 我有一個點擊向 API 發送請求以下載檔案,但它不起作用請求發送成功但檔案沒有下載,但是當我正在將 URL 添加到瀏覽器中,檔案已成功下載
HTML
<button (click)="exportFile()">Download</button>
TS
exportFile(): void{
this.companiesService.export().subscribe((res) => {
console.log(res);
});
}
服務
export(){
const headers = this.httpOptions.headers.set('Authorization', `Bearer ${this.cookieService.get('access-token')}`);
return this.http.get(`${this.API_URL}/company/export/`,{headers});
}
uj5u.com熱心網友回復:
您需要處理回傳的 blob 并將其保存為檔案。僅僅退貨是不夠的。也許這個演示可以讓您更深入地了解如何改進您的服務。https://stackblitz.com/edit/angular-file-download-progress-qsqsnf?file=src/app/download.ts
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/422462.html
標籤:
