使用 Angular 从 s3 的预签名 URL 下载文件

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

目标:

我的角度应用程序需要从 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)
  })
amazon-s3 http-headers httpclient pre-signed-url preflight
1个回答
0
投票

已解决

将此配置添加到您的 AWS s3 存储桶中:

[
 {
    "AllowedHeaders": [
        "*"
    ],
    "AllowedMethods": [
        "GET",
        "HEAD"
    ],
    "AllowedOrigins": [
        "*"
    ],
    "ExposeHeaders": []
 }
]
© www.soinside.com 2019 - 2024. All rights reserved.