【问题标题】:Download CSV through REST Api通过 REST Api 下载 CSV
【发布时间】:2020-01-21 14:03:13
【问题描述】:

我必须从 REST Api 下载 CSV。 我正在通过我的服务进行 Http 获取请求

user.service.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

customer-list.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 文档中请求数据

【问题讨论】:

    标签: angular typescript rest csv


    【解决方案1】:

    使用{ responseType: 'blob' }

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

    【讨论】:

      猜你喜欢
      • 2014-03-19
      • 2014-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-14
      • 1970-01-01
      • 2017-01-25
      • 2016-06-03
      相关资源
      最近更新 更多