簡體   English   中英

下載 CSV 至 REST Api

[英]Download CSV through REST Api

我必須從 REST Api 下載 CSV。 我正在做 Http 通過我的服務獲取請求

用戶服務.ts

  public downloadCsv(target: string): Observable<any> {
    return this.http.get<any>(
      this.api.getUrl(environment.api.endpoints.download).replace('{target}', target)
    ).pipe(
      catchError(this.api.handleError)
    );
  }

並在我的組件中訂閱 observable

客戶列表.component.ts

  downloadCsv() {
    this.userService.downloadCsv('users_ub').subscribe(
      (response) => {

      }
    );
  }

我收到一個錯誤

VM73806 vendor.js:56089 ERROR Error Code: 200
Message: Http failure during parsing for http://localhost:90/api/download/csv/users_ub.csv

在 chrome 開發工具中請求數據(角度)

從我的 api 文檔請求數據

在此處輸入圖像描述

使用{ responseType: 'blob' }

this.http.get<any>(url,{ responseType: 'blob' })

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM