amazon S3 upload API 对 http post 参数排序敏感

amazon S3 upload API is sensitive to http post parameter ordering

我创建了一个存储桶,其中的政策规定必须指定要上传的对象的内容类型。如果我在文件元素之后指定内容类型,(下面的示例)

<form action="..">
...
<input type='file' name='file' />
<input name='content-type' value='image/jpeg' />
<input type='submit' />
</form>

它 return 之后出现错误

<Error>
    <Code>AccessDenied</Code>
    <Message>Invalid according to Policy: Policy Condition failed: ["starts-with", "$Content-Type", ""]</Message>
    <RequestId>15063EB427B4A469</RequestId>
    <HostId>yEzAPF4Z2inaafhcqyQ4ooLVKdwnsrwqQhnYg6jm5hPQWSOLtPTuk0t9hn+zkBEbk+rP4S5Nfvs=</HostId>
</Error>

如果我在文件元素之前指定内容类型,上传将按预期进行。我第一次遇到这种行为。我有几个问题。

  1. 它是否是某些规范的一部分,其中客户端和所有中间代理应该维护 http post 参数的顺序?请指点一下。

  2. 为什么要让 API 知道这样的排序?在这种特殊情况下,我可以猜测该文件可能很大,除非您之前看到所有预期的参数,否则您应该立即 return 失败。如果我的理解不正确,请指正。

It is part of the spec that the parts are sent as ordered in the form。没有理由相信会允许通过中间代理重新排序。

The form data and boundaries (excluding the contents of the file) cannot exceed 20K.

...

The file or content must be the last field in the form.

http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTForms.html#sigv4-HTTPPOSTFormFields

逻辑假设是此设计允许 S3 及早拒绝无效上传。