Nyeon Kim
Nyeon Kim

Reputation: 137

Error: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource

I requests s3 server through axios, and I got Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Also, before that, I got OPTIONS https://s3.ap-northeast-2.amazonaws.com/.../... 403 (Forbidden)

I should solve this problem in client-side. I am hosting my files on my local machine. My request codes are below.

axios({
  url: 'https://s3.ap-northeast-2.amazonaws.com/.../...',
  method: 'get',
  withCredentials: true,
  headers: {
    'Content-Type': 'image/jpeg',
    'Access-Control-Allow-Origin': 'http://*, https://*',
  }

})

I tried

  1. start chrome --disable-web-security using git
  2. Installed chrome plugin - Allow-Control-Allow-Origin: *

nothing worked... How can I solve this problem?

Upvotes: 5

Views: 8855

Answers (1)

Michael - sqlbot
Michael - sqlbot

Reputation: 179074

Access-Control-Allow-Origin is a response header, not a request header. You can't fix this locally, because it's a problem on the other end.

You need CORS (Cross Origin Resource Sharing) enabled and configured on the S3 bucket you are trying to access.

http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html

Upvotes: 4

Related Questions