2017-06-29 63 views
0

我一直在尝试一天,但我无法修复它。它在控制台中出现了这个错误。无法上传图片到S3使用Froala

XMLHttpRequest cannot load https://s3-us-east-2.amazonaws.com/My-bucket. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access. 

,这是我对Angular2

imageUploadToS3: { 

bucket: 'flagfrog-article-cloud', 
region: 's3-us-east-2', 
keyStart: 'article-image/', 
params: { 
    acl: 'public-read', // ACL according to Amazon Documentation. 
    AWSAccessKeyId: 'AKIAJEMDZVXVLMPDNA4A', // Access Key from Amazon. 
    policy: 'Policy1498724219240', // Policy string computed in the backend. 
    signature: 'flagfrogweb', // Signature computed in the backend. 
} 

代码这是亚马逊S3我CORS配置。

`<?xml version="1.0" encoding="UTF-8"?> 
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> 
<CORSRule> 
    <AllowedOrigin>*</AllowedOrigin> 
    <AllowedMethod>GET</AllowedMethod> 
    <AllowedMethod>PUT</AllowedMethod> 
    <AllowedMethod>POST</AllowedMethod> 
    <AllowedMethod>DELETE</AllowedMethod> 
    <MaxAgeSeconds>3000</MaxAgeSeconds> 
    <AllowedHeader>Authorization</AllowedHeader> 
</CORSRule> 
</CORSConfiguration> 
` 

我在这里错过了什么吗?请帮助

回答

0

亚马逊不允许通配符来源。你的CORS配置应该是这样的:

<?xml version="1.0" encoding="UTF-8"?> 
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/"> 
<CORSRule> 
    <AllowedOrigin>http://localhost:4200</AllowedOrigin> 
    <AllowedMethod>GET</AllowedMethod> 
    <AllowedMethod>PUT</AllowedMethod> 
    <AllowedMethod>POST</AllowedMethod> 
    <AllowedMethod>DELETE</AllowedMethod> 
    <MaxAgeSeconds>3000</MaxAgeSeconds> 
    <AllowedHeader>Authorization</AllowedHeader> 
</CORSRule> 
</CORSConfiguration> 
+0

我确实试过你建议我。它不起作用。仍然有相同的错误。 *是否允许每个通配符? – Letmetake

+0

亚马逊不允许'*'为AllowedOrigin。您应该放置该网页的网址。 – st3fan

+0

现在我得到了其他错误。这是“选项https://s3-ap-southeast-1.amazonaws.com/flagfrog-article-cloud 403(禁止)”。当我点击它时,它会显示“我们计算的请求签名与您提供的签名不匹配,请检查您的密钥和签名方法。”任何建议?非常感谢 – Letmetake