Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

like image 891
Nyeon Kim Avatar asked May 12 '17 02:05

Nyeon Kim


People also ask

How do I fix CORS policy no Access-Control allow origin?

To allow any site to make CORS requests without using the * wildcard (for example, to enable credentials), your server must read the value of the request's Origin header and use that value to set Access-Control-Allow-Origin , and must also set a Vary: Origin header to indicate that some headers are being set ...

How do you solve CORS preflight request?

Simple Requests. Another way to avoid Preflight requests is to use simple requests. Preflight requests are not mandatory for simple requests, and according to w3c CORS specification, we can label HTTP requests as simple requests if they meet the following conditions. Request method should be GET , POST , or HEAD .

Is not allowed by Access-Control allow origin?

This error occurs when a script on your website/web app attempts to make a request to a resource that isn't configured to accept requests coming from code that doesn't come from the same (sub)domain, thus violating the Same-Origin policy.

What does Access-Control allow Origin header do?

What is the Access-Control-Allow-Origin response header? The Access-Control-Allow-Origin header is included in the response from one website to a request originating from another website, and identifies the permitted origin of the request.


1 Answers

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

like image 109
Michael - sqlbot Avatar answered Sep 21 '22 10:09

Michael - sqlbot