[英]AWS S3 File Upload, getting No 'Access-Control-Allow-Origin' error
I am uploading file to S3 using ajax method. 我正在使用ajax方法将文件上传到S3。 My file is successfully uploaded (got 204 code) but still (ajax is going in fail method instead of success) getting error, No 'Access-Control-Allow-Origin' header is present on the requested resource.
我的文件已成功上传(获取204代码),但仍然(ajax采用失败方法而不是成功方法)出错,所请求的资源上没有'Access-Control-Allow-Origin'标头。
my crossdomain policy is as follows, 我的跨域政策如下
<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
<allow-http-request-headers-from domain="*" headers="*">
</allow-http-request-headers-from>
</cross-domain-policy>
my ajax method, 我的ajax方法
$.ajax({
url : url,
type: "POST",
data: data,
contentType: false,
processData: false,
success: function(){
console.log("success")
},
error: function(){
console.log("error")
}
})
Please read this document http://docs.aws.amazon.com/AmazonS3/latest/UG/EditingBucketPermissions.html 请阅读此文档http://docs.aws.amazon.com/AmazonS3/latest/UG/EditingBucketPermissions.html
Below is the sample xml you can try. 以下是您可以尝试的示例XML。 Change the
examplesite.com
to yours. 将
examplesite.com
更改为您的。 Right click the bucket and go to "Permissions" tab and click "Edit CORS Configuration" 右键单击存储桶,然后转到“权限”标签,然后单击“编辑CORS配置”
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>Authorization</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>http://*.examplesite.com</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
</CORSRule>
</CORSConfiguration>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.