Unable to update AWS S3 CORS POLICY

前端 未结 3 2038
没有蜡笔的小新
没有蜡笔的小新 2021-02-19 10:18

I needed to change my AWS S3 bucket CORS policy to enable the upload of files for my ReactJS to AWS S3, but I keep getting this API response:

Expected params

相关标签:
3条回答
  • 2021-02-19 10:54

    I'm not sure if this helps. I ran into this same problem recently and it seems like AWS made some changes with how we define our CORS configurations. For example, if you want to allow certain Methods on your S3 bucket in the past you have to do something like this on the editor:

    <CORSConfiguration>
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>POST</AllowedMethod>
        <AllowedMethod>HEAD</AllowedMethod>
        <AllowedMethod>DELETE</AllowedMethod>
        <MaxAgeSeconds>3000</MaxAgeSeconds>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
    

    The config below is equivalent to the one on the top but takes the form of an array.

    [
        {
            "AllowedHeaders": [
                "*"
            ],
            "AllowedMethods": [
                "GET",
                "PUT",
                "POST",
                "HEAD",
                "DELETE"
            ],
            "AllowedOrigins": [
                "*"
            ],
            "ExposeHeaders": [],
            "MaxAgeSeconds": 3000
        }
    ]
    

    Let me know if this helps. Thank you!

    0 讨论(0)
  • 2021-02-19 10:59

    We encountered the same error. We needed two fixes. (Not sure if this is helpful in your case):

    1. Pay attention to the type of quotes used: "" vs “”. Use the former
    2. Make sure you do not have a trailing comma on the second to last line, following the bracket.
    0 讨论(0)
  • To configure CORS for your static website the CORS object has to be in JSON format see aws docs cors configuration. To specify the actions allowed on that bucket you want to enable CORS on, you must define a set of CORS Rules. The CORS Rules is an array that holds a set of objects where each object corresponds to a particular rule. To learn more about how to define CORS Rules see aws cors rule. The error you are receiving is due the fact that your CORS Rule is in improper format. If you follow the above example by @FaitAccompli the error should be resolved.

    0 讨论(0)
提交回复
热议问题