从文件下载角2获取文件名

问题描述 投票:2回答:1

我似乎无法获得内容处置头露面。我只能看到的Content-Type。这是在我的回应虽然。

public openAttachment(id: number) {
this.http
  .get(`${this.startupService.baseUrl}company/${this.company.companyID}/attachment/${id}`,
     {responseType: 'blob', observe: 'response'})
  .subscribe(data => {
    console.log(data);

    const contentDis = data.headers.get('content-disposition');
    console.log(contentDis);

    const contentType = data.headers.get('content-type');
    console.log(contentType);
  });
}    

下面是我的控制台日志的副本:

enter image description here

和这里的响应:

enter image description here

angular typescript
1个回答
2
投票

它似乎并没有成为你的代码的错误。

如果“访问控制展露-头”是不是在你的后端设置正确,浏览器客户端代码不能访问它。

因此,检查和设置Access-Control-Expose-Headers(‘Content-Disposition’)在你的后端代码。

https://jaketrent.com/post/expose-http-headers-in-cors/链接可能是在这种情况下有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.