我成功地使用curl作为POC来动态计算签名并将用户文件直接计算到Amazon S3:Direct file upload to S3 using sigv4
现在我正在处理我的真实案例:使用POST进行基于浏览器的上传。
我按照此处所述的说明操作:http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html
我正在计算我的签名并使用相应的表单 - 减去一些字段(请参阅下面的表格)。
奇怪的是,我在表单提交后出现错误(参见下面的 MissingSignatureError )...我被迫添加一个“签名”字段,该字段在亚马逊示例表单中不存在。 当我用“签名”替换“X-Amz-Signature”字段时,会出现典型的“ SignatureDoesNotMatch ”错误。
这对我来说似乎很奇怪。 为什么是这样 ?亚马逊不是自动的。使用Sigv4?亚马逊文档是否不正确?
表格
<form action="https://??.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
Key to upload: <input type="input" name="key" value="recordtest/testpost.jpg" /><br />
Content-Type: <input type="input" name="Content-Type" value="image/jpeg" /><br />
<input type="hidden" name="AWSAccessKeyId" value="??" />
<input type="text" name="X-Amz-Credential" value="??/eu-west-1/s3/aws4_request" />
<input type="text" name="X-Amz-Algorithm" value="AWS4-HMAC-SHA256" />
<input type="text" name="X-Amz-Date" value="20170301T173312Z" />
<input type="hidden" name="Policy" value="eyAiZXhwaXJhdGlvbiI6ICIyMDE3LTAzLTAxVDE4OjMzOjEyLjc0MFoiLAogICJjb25kaXRpb25zIjogWwogICAgeyJidWNrZXQiOiAidGVsbWVkLXRlc3QifSwKICAgIHsieC1hbXotY3JlZGVudGlhbCI6ICJBS0lBSlA1STZaS1JPUkpHNDZaQS8yMDE3MDMwMS9ldS13ZXN0LTEvczMvYXdzNF9yZXF1ZXN0In0sCiAgICB7IngtYW16LWFsZ29yaXRobSI6ICJBV1M0LUhNQUMtU0hBMjU2In0sCiAgICB7IngtYW16LWRhdGUiOiAiMjAxNzAzMDFUMTczMzEyWiJ9CiAgXQp9" />
<input type="hidden" name="X-Amz-Signature" value="38f054500c98f0df20a3bdb165d3a24659dafd5c7f9c8961f7aaa1694660a980" />
File: <input type="file" name="file" /> <br />
<!-- The elements after this will be ignored -->
<input type="submit" name="submit" value="Upload to Amazon S3" />
</form>
MissingSignatureError
<Error>
<Code>InvalidArgument</Code>
<Message>
Bucket POST must contain a field named 'Signature'. If it is specified, please check the order of the fields.
</Message>
</Error>
SignatureDoesNotMatch
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the signature you provided. Check your key and signing method.
</Message>
...
</Error>