Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 即使在添加CORS配置后,S3也会出现CORS错误_Javascript_Amazon S3_Cors - Fatal编程技术网

Javascript 即使在添加CORS配置后,S3也会出现CORS错误

Javascript 即使在添加CORS配置后,S3也会出现CORS错误,javascript,amazon-s3,cors,Javascript,Amazon S3,Cors,我试图通过javaScript将图像上传到S3存储桶。提交请求时,返回以下错误: XMLHttpRequest cannot load https://somebucket.s3-us-west 2.amazonaws.com/albums//apicture.png. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is pres

我试图通过javaScript将图像上传到S3存储桶。提交请求时,返回以下错误:

XMLHttpRequest cannot load https://somebucket.s3-us-west 
2.amazonaws.com/albums//apicture.png. Response to preflight 
request doesn't pass access control check: No 'Access-Control-Allow-Origin'
header is present on the requested resource. 
Origin 'http://someorigin:3000' is therefore not allowed access.
桶上的我的CORS配置:

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>http://someorigin:3000</AllowedOrigin>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <AllowedMethod>HEAD</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
响应
选项卡还有一些其他重要信息:

Request URL:https://somebucket.s3-us-west-2.amazonaws.com/pics/apicture.png
Request Method:OPTIONS
Status Code:301 Moved Permanently
<Error>
<Code>PermanentRedirect</Code>
<Message>The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.</Message>
<Bucket>somebucket</Bucket>
<Endpoint>somebucket.s3-us-west-1.amazonaws.com</Endpoint>
<RequestId>
***************
</RequestId>
</Error>

因此,很明显,他们希望该区域为
us-west-1
,但是,如果我将
AWS.config
更改为该区域,则会抛出不同的错误。亚马逊自己的指南说,“北加利福尼亚”地区的编码为
us-west-2
,所以我不确定为什么会有这种不一致

AWS S3 Bucket=>添加元数据“缓存控制”:“无缓存”

现在需要在JSON中设置。 权限->CORS

[{
    "AllowedHeaders": [
        "*"
    ],
    "AllowedMethods": [
        "GET"
    ],
    "AllowedOrigins": [
        "*"
    ],
    "ExposeHeaders": []
}]

对飞行前的响应
-似乎是飞行前失败了-您使用的是什么http方法(GET、POST等)以及什么请求头-检查开发人员工具网络选项卡以查看您的网络流量详细信息request@JaromandaX在“请求标题”下有许多。你有什么特别的想法吗?没有,只是非标准的会触发预飞-根据消息,这显然是故障点-对amazon-s3不熟悉,所以我真的帮不上忙,除了指出是预飞(即选项调用)失败,而bucket实际上在哪个区域?北加利福尼亚州是美国西部1号,而不是美国西部2号(俄勒冈州)。水桶位于北加利福尼亚州。如果我将代码更改为us-west-1,它会显示“OPTIONS net::ERR_NAME_NOT_RESOLVED”,可能是因为标识池Id在us-west-2中,但我无法更改它,所以我真的迷路了。