English 中文(简体)
将表格数据张贴到亚马逊S3桶
原标题:Posting form data to Amazon S3 bucket

I ve spent three days now trying to set up a simple posting form to amazon s3. Everytime I get this error:

SignatureDoesNotMatchThe request signature we calculated does not match the signature you provided. Check your key and signing method.

我没看到问题所在。

<?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>

我替换了桶名以及上面的私人和公共钥匙。

I followed the instruction to sign the policy meticulously: http://docs.amazonwebservices.com/AmazonS3/2006-03-01/dev/HTTPPOSTForms.html#HTTPPOSTConstructPolicy

我错过什么了 为什么密码不起作用

最佳回答

Okay, I finally managed to get this done using this sample code library: http://aws.amazon.com/code/Amazon-S3/1618

问题回答

不需要该库, 您刚刚丢失了一个参数。 问题在于您没有将 hash_ hmac 函数设置为输出二进制数据。 要做到这一点, 请将第四个参数设置为 true 类似 :

$signature = base64_encode(hash_hmac( sha1 , $policy_b64, $secret, true));

如果您不设置此选项, 它将不会像 AWS 所期望的那样将签名编码 。

我已经回答了你自己的问题,我知道,但我想知道这个辅导(http://aws.amazon.com/articles/1434 )是否是问题的根源,这说明你必须先把返回的字符从json上除掉,然后才做64码?





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...