我已经花了三天时间尝试为亚马逊 s3 设置一个简单的发布表单。每次我得到这个错误:
SignatureDoesNotMatch 我们计算的请求签名与您提供的签名不匹配。检查您的密钥和签名方法。
我没有看到问题。:-(
<?php
$form = array(
'key' => 'queue/1_1_1234567890.wmv',
'AWSAccessKeyId' => 'mypublickeyishere',
'acl' => 'public-read',
'success_action_redirect' => 'http://someurl.com',
);
$form['policy'] = '{
"expiration": "2015-12-01T12:00:00.000Z",
"conditions": [
{
"acl": "'.$form['acl'].'"
},
{
"success_action_redirect": "'.$form['success_action_redirect'].'"
},
{
"bucket": "thenameofmybucket"
},
[
"starts-with",
"$key",
"queue/"
]
]
}';
$form['policy_encoded'] = base64_encode($form['policy']);
$form['signature'] = base64_encode(hash_hmac( 'sha1', base64_encode(utf8_encode($form['policy'])), 'F90mc5kpjuNMPg8XG7iV6bxOzacYhktcw+RVGzpZ'));
?>
<form action="https://thenameofmybucket.s3.amazonaws.com/" method="post" enctype="multipart/form-data">
<input type="hidden" name="key" value="<?php echo $form['key'] ?>">
<input type="hidden" name="AWSAccessKeyId" value="<?php echo $form['AWSAccessKeyId'] ?>">
<input type="hidden" name="acl" value="<?php echo $form['acl'] ?>">
<input type="hidden" name="success_action_redirect" value="<?php echo $form['success_action_redirect'] ?>">
<input type="hidden" name="policy" value="<?php echo $form['policy_encoded'] ?>">
<input type="hidden" name="signature" value="<?php echo $form['signature'] ?>">
File to upload to S3:
<input name="file" type="file">
<br>
<input type="submit" value="Upload File to S3">
</form>
我替换了存储桶名称以及上面的私钥和公钥。
我按照说明仔细签署了政策:http: //docs.amazonwebservices.com/AmazonS3/2006-03-01/dev/HTTPPOSTForms.html#HTTPPOSTConstructPolicy
我错过了什么?为什么代码不起作用?