Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49083

CORS issue when uploading to AWS S3, and I'm not supposed to use cordova or fix it on the AWS, but on the client side

$
0
0

I’m using http get methods and subscribing to the data that I need to read. Here’s the example code

  getC(a,b):Observable<any>  {
      return this.http.get<C[]>(ENV.BUILD_PATH+a+"/"+b+"/"+"c.json");    
  }

Here also I had the CORS issue, but I fixed it with the chrome plugin to fix the CORS issue. So now I have the loaded data, but I need to change the data and then upload and overwrite the existing data on the JSON file. My upload looks like follows.

uploadToS3 = async (data: JSON, fileName:string, path) => {
    const params = {
      Bucket: environment.bucketName,
      Key: path+fileName,
      Body: data,
      ACL: 'public-read',
      ContentType: 'application/json'
    };

    await this.s3.putObject(params, (err, data) => {
      if (err) {
        throw err;
      }
      console.log(`File uploaded successfully.`);
      }
    );

But I get errors like this

Access to XMLHttpRequest at ‘https://bucketName.s3.region.amazonaws.com/bucketName/folderName/fileName.json’ from origin ‘http://localhost:8100’ has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: It does not have HTTP ok status.

Can someone tell me what is the issue?, thanks in advance

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 49083

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>