admin管理员组文章数量:1287826
I have an amplify application; that upload files to S3 bucket. It worked at the beginning until I'm starting to see errors on CORS Put requests to the s3 bucket on the Chrome console:
Access to XMLHttpRequest at '/normalpicture3.png?x-id=PutObject' from origin '' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
The relevant code which is failing:
async function onChange(e) {
if (props.onChange) {
await props.onChange(e);
}
setProgress(0);
const file = e.target.files[0];
setFilename(file.name);
try {
var response = await Storage.put(file.name, file, {
progressCallback(progress) {
setProgress(progress.loaded * 100 / progress.total);
},
level: props.level,
useAccelerateEndpoint: true,
region: "us-east-1",
bucket: "amplify-ofmawsdemoenhanced-dev-5108d-deployment"
});
setUploaded(true);
} catch (error) {
console.log("Error uploading file: ", error);
}
var responseIdentify = await onIdentify(file);
var responseInterpret = await onInterpret(responseIdentify.text.fullText);
}
But I do seem to have the right CORS configuration on the bucket:
aws s3api get-bucket-cors --bucket amplify-ofmawsdemoenhanced-dev-5108d-deployment
{
"CORSRules": [
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"PUT",
"POST",
"DELETE",
"HEAD"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": [
"Access-Control-Allow-Origin",
"Access-Control-Allow-Methods",
"Access-Control-Request-Headers",
"Access-Control-Request-Method",
"Origin"
]
}
]
}
Tried to troubleshoot different configurations, re-running the app.
本文标签:
版权声明:本文标题:amazon s3 - AWS Amplify Gen 1: blocked by CORS policy: Response to preflight request doesn't pass access control check - 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741325144a2372430.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论