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
start chrome --disable-web-security
using gitnothing worked... How can I solve this problem?
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 ...
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 .
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 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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With