[英]Not able to get the `Content-Disposition` from backend response
I am trying to get the value from Content-Disposition
from my backend response. 我正在尝试从后端响应中从
Content-Disposition
获取值。 but I am not able to get that at all.. 但我根本无法理解。
here is my code : 这是我的代码:
public getQuoteImage(sharedQuote):Observable<any> {
return this.http.post(environment.downloadSummarUrl, JSON.stringify(sharedQuote), {
headers: this.params.headers.validate,
observe: "response",
responseType : 'blob'
});
}
I am trying to get filename
from Content-Disposition
from the following: 我正在尝试从以下
Content-Disposition
从Content-Disposition
获取filename
:
downloadSummaryContent() {
this.server.getQuoteImage(this.sharedQuote).subscribe((data) => {
console.log( 'headers are', '\n', data, '\n', data.headers.get('Content-Disposition') ); //but not getting the file name
var url = window.URL.createObjectURL(data);
var a = document.createElement('a');
document.body.appendChild(a);
a.setAttribute('style', 'display: none');
a.href = url;
a.download = 'quote.pdf';
a.click();
window.URL.revokeObjectURL(url);
a.remove(); // remove the element
});
}
But not getting the value at all. 但根本无法获得价值。
in the console i am getting: 在控制台中,我得到:
{
"headers": {
"normalizedNames": {
},
"lazyUpdate": null,
"lazyInit": null,
"headers": {
}
},
"status": 200,
"statusText": "OK",
"url": "https:XXXXXXservice/p/shipment/download/",
"ok": true,
"type": 4,
"body": {
}
}
According to MDN Access-Control-Expose-Headers documentation , CORS requests only allows javascript to access the following response headers: 根据MDN Access-Control-Expose-Headers文档 ,CORS请求仅允许javascript访问以下响应头:
The server can allow access to other response headers using the Access-Control-Expose-Headers
response, so, for Content-Disposition
to be accessible to the client, you would need to issue 服务器可以使用
Access-Control-Expose-Headers
响应允许访问其他响应头,因此,要让客户端可以访问Content-Disposition
,您需要发出
Access-Control-Expose-Headers: Content-Disposition
header in the response 响应中的标题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.