【问题标题】:Can't upload image to S3 using Froala无法使用 Froala 将图像上传到 S3
【发布时间】:2017-07-10 15:15:46
【问题描述】:

我已经尝试了一天,但我无法修复它。它在控制台中出现此错误。

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.
}

这是我在 Amazon 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>
`

我在这里遗漏了什么吗?请帮忙

【问题讨论】:

    标签: angular amazon-s3 xmlhttprequest froala


    【解决方案1】:

    亚马逊不允许通配符来源。你的 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>
    

    【讨论】:

    • 我确实尝试过你建议我。它不起作用。仍然有同样的错误。 * 是否意味着允许每个通配符?
    • 亚马逊不允许 * 用于 AllowedOrigin。您应该输入页面的 URL。
    • 现在我得到了其他错误。它是“选项s3-ap-southeast-1.amazonaws.com/flagfrog-article-cloud 403(禁止)”。当我点击它时,它显示“我们计算的请求签名与您提供的签名不匹配。请检查您的密钥和签名方法。”。有什么建议吗?非常感谢
    • 很可能签名计算不正确。请参阅here 和使用 Node 计算签名的示例。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-17
    • 2020-07-07
    • 2017-01-29
    • 2019-09-30
    • 1970-01-01
    • 2017-07-29
    • 1970-01-01
    相关资源
    最近更新 更多