获取从Http Post的标题导出的文件的名称[angular4]

时间:2018-08-22 08:08:10

标签: typescript http-post angular4-httpclient

我需要根据http帖子发送的标题设置导出的excel的名称。

这是我的代码:

  

component.ts

  public getAccordo(event: any): any {
    event.preventDefault();
    this.accordiService.getAccordo(this.filter).subscribe(
      data => {
        const blob = new Blob([data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
        const anchor = document.createElement('a');
        anchor.href = window.URL.createObjectURL(blob);
        anchor.download = data
        anchor.click();
      },
      error => {
        console.log(error);
      }
    );
  }
  

service.ts

   getAccordo(filtro: Filter) {
        return this.http.post<any>(
            `${this.ENDPOINT}/export`,
            filter,
            { responseType: 'blob' as 'json' }
        )
    }
  

响应头:

enter image description here

0 个答案:

没有答案