目标:
我的角度应用程序需要从 AWS S3 预签名 URL 读取此 json 文件
问题:
当我尝试使用 http 调用来自 S3 存储桶的预签名 URL 时,出现错误,
https://mydomain
has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
服务.ts:
getPreSignedUrl(url: string): Observable<any>{
return this.http.get<any>(url)
}
app.component.ts
const url = 'https://s3.amazonaws.com/etc';
this.service.getPreSignedUrl(url)
.subscribe(data=> {
console.log(data)
})
已解决:
将此配置添加到您的 AWS s3 存储桶中:
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"HEAD"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]