Download a file from pre-signed url from s3 using Angular

30 views Asked by At

Goal:

My angular app needs to read this json file from AWS S3 Pre-signed URL

Problem:

When I'm trying to get with http call a Pre-signed URL from S3 bucket, I'm getting an error,

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.

service.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)
  })
1

There are 1 answers

0
Naor Yael On

SOLVED:

add this config to your AWS s3 bucket:

[
 {
    "AllowedHeaders": [
        "*"
    ],
    "AllowedMethods": [
        "GET",
        "HEAD"
    ],
    "AllowedOrigins": [
        "*"
    ],
    "ExposeHeaders": []
 }
]