Amazon s3 AWS S3 Post对象拒绝额外的表单字段

Amazon s3 AWS S3 Post对象拒绝额外的表单字段,amazon-s3,storage,Amazon S3,Storage,我正在尝试将上传图像的存储类设置为AWS S3存储桶。除了向请求中添加存储类之外,我还可以使用它。状态可以是名为“x-amz-storage-class”的表单输入字段,但添加该字段或任何其他字段都会引发AWS错误,表明post的输入字段过多。我尝试将其添加到对象策略中,但这会导致策略错误:“策略条件失败:[“eq”、“$x-amz-storage-class”、“ONEZONE_IA”]”。我正在使用JSP,表单的输入字段如下所示。任何帮助都将不胜感激 <input type="

我正在尝试将上传图像的存储类设置为AWS S3存储桶。除了向请求中添加存储类之外,我还可以使用它。状态可以是名为“x-amz-storage-class”的表单输入字段,但添加该字段或任何其他字段都会引发AWS错误,表明post的输入字段过多。我尝试将其添加到对象策略中,但这会导致策略错误:“策略条件失败:[“eq”、“$x-amz-storage-class”、“ONEZONE_IA”]”。我正在使用JSP,表单的输入字段如下所示。任何帮助都将不胜感激

<input type="hidden" name="key" value="<%= imageFileName %>">
<input type="hidden" name="AWSAccessKeyId" value="<%= S3AccessKeyId %>"> 
<input type="hidden" name="acl" value="private"> 
<input type="hidden" name="success_action_redirect" value="<%= s3SuccessAction %>">
<input type="hidden" name="policy" value="<%= encPolicy %>" >
<input type="hidden" name="signature" value="<%= signature %>" >
<input type="hidden" name="Content-Type" value="image/jpeg">
<input type="hidden" name="x-amz-storage-class" value="ONEZONE_IA">   ***** CAUSES ERROR ****

我现在正在工作。策略包含的字段必须与表单上的字段匹配。“x-amz-storage-class”必须添加到表单字段和策略中。我的猜测是,加密策略是出于安全原因而签名的,这使得它更加安全,表单字段必须与策略字段匹配,以确保它们不会被更改。我无法理解为什么两者都需要。更正代码如下:

<fieldset>

    <input type="hidden" name="key" value="<%= imageFileName %>">
    <input type="hidden" name="AWSAccessKeyId" value="<%= S3AccessKeyId %>"> 
    <input type="hidden" name="acl" value="private"> 
    <input type="hidden" name="success_action_redirect" value="<%= s3SuccessAction %>">
    <input type="hidden" name="policy" value="<%= encPolicy %>" >
    <input type="hidden" name="signature" value="<%= signature %>" >
    <input type="hidden" name="Content-Type" value="image/jpeg">
    <input type="hidden" name="x-amz-storage-class" value="ONEZONE_IA">
    

public static String encodeS3Policy(String s3SuccessAction, String bucket) throws Exception
{
    String policy =
        "{\"expiration\": \"2040-01-01T00:00:00Z\"," +
          "\"conditions\": [" +
            "{\"bucket\": \"" + bucket + "\"}," +
            "[\"starts-with\", \"$key\", \"\"]," +
            "{\"acl\": \"private\"}," +
            "{\"success_action_redirect\": \"" + s3SuccessAction + "\"}," +
            "[\"starts-with\", \"$Content-Type\", \"\"]," +
            "{\"x-amz-storage-class\": \"ONEZONE_IA\"}," +
            "[\"content-length-range\", 0, 10485760]" +                                 // 10 MB max file up load
            "]" +
        "}";

    policy.replaceAll("\n","").replaceAll("\r","");


    // Encode the policy
    String encPolicy = Base64.getEncoder().encodeToString(policy.getBytes("UTF-8"));

    return encPolicy;
}

这是

确切的错误是什么?我检查了错误代码,没有发现任何表明输入字段过多的错误。我修改了问题,添加了错误。“根据策略无效:额外输入字段:x-amz-storage-class”。无论字段名是什么,它都会使用适当的字段名抛出此错误。
<fieldset>

    <input type="hidden" name="key" value="<%= imageFileName %>">
    <input type="hidden" name="AWSAccessKeyId" value="<%= S3AccessKeyId %>"> 
    <input type="hidden" name="acl" value="private"> 
    <input type="hidden" name="success_action_redirect" value="<%= s3SuccessAction %>">
    <input type="hidden" name="policy" value="<%= encPolicy %>" >
    <input type="hidden" name="signature" value="<%= signature %>" >
    <input type="hidden" name="Content-Type" value="image/jpeg">
    <input type="hidden" name="x-amz-storage-class" value="ONEZONE_IA">
    

public static String encodeS3Policy(String s3SuccessAction, String bucket) throws Exception
{
    String policy =
        "{\"expiration\": \"2040-01-01T00:00:00Z\"," +
          "\"conditions\": [" +
            "{\"bucket\": \"" + bucket + "\"}," +
            "[\"starts-with\", \"$key\", \"\"]," +
            "{\"acl\": \"private\"}," +
            "{\"success_action_redirect\": \"" + s3SuccessAction + "\"}," +
            "[\"starts-with\", \"$Content-Type\", \"\"]," +
            "{\"x-amz-storage-class\": \"ONEZONE_IA\"}," +
            "[\"content-length-range\", 0, 10485760]" +                                 // 10 MB max file up load
            "]" +
        "}";

    policy.replaceAll("\n","").replaceAll("\r","");


    // Encode the policy
    String encPolicy = Base64.getEncoder().encodeToString(policy.getBytes("UTF-8"));

    return encPolicy;
}
Default: STANDARD

STANDARD | REDUCED_REDUNDANCY | GLACIER | STANDARD_IA | ONEZONE_IA | INTELLIGENT_TIERING | DEEP_ARCHIVE