0

I tried a file upload to my amazon s3 refering this tutorial http://www.anyexample.com/programming/php/uploading_files_to_amazon_s3_with_rest_api.xml

But I got the following error

HTTP/1.1 403 Forbidden
x-amz-request-id: 10F111F91A85CFC5
x-amz-id-2: 6pBJs+OKZOZdTF3zQw0MLM62zGAAsCFyeJsv/xzYB+wM7+7RnZU+k1rtcpTWC8VS
Content-Type: application/xml
Transfer-Encoding: chunked
Date: Fri, 02 Dec 2011 09:35:21 GMT
Server: AmazonS3

2bf
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<StringToSignBytes>50 55 54 0a 0a 0a 46 72 69 2c 20 30 32 20 44 65 63 20 32 30 31 31 20 30 39 3a 33 37 3a 35 30 20 2b 30 30 30 30 0a 2f 74 61 6e 65 77</StringToSignBytes>
<RequestId>10F111F91A85CFC5</RequestId>
<HostId>6pBJs+OKZOZdTF3zQw0MLM62zGAAsCFyeJsv/xzYB+wM7+7RnZU+k1rtcpTWC8VS</HostId>
<SignatureProvided>6V2sLdHEJ9uWZO0G81q5QQzSa9Y=</SignatureProvided><StringToSign>PUT

Any Ideas Thanks in advance

5
  • 2
    Is The request signature we calculated does not match the signature you provided. Check your key and signing method. not clear already? Commented Dec 2, 2011 at 10:00
  • they following is the signing method... Can you please help ? $dt = gmdate('r'); // GMT based timestamp // preparing String to Sign (see AWS S3 Developer Guide) $string2sign = "PUT {$dt}/{$aws_bucket}"; // preparing HTTP PUT query $query = "PUT /{$aws_bucket} HTTP/1.1 Host: s3.amazonaws.com Connection: keep-alive Date: $dt Authorization: AWS {$aws_key}:".amazon_hmac($string2sign)."\n\n"; $resp = sendREST($fp, $query); if (strpos($resp, '<Error>') !== false) { die($resp); } Commented Dec 2, 2011 at 10:15
  • 1
    do you have your own AWS Access Key ID and secret access key? Commented Dec 2, 2011 at 10:17
  • yes I had my own Access Key ID and secret access key Commented Dec 2, 2011 at 10:19
  • @rajeesh I have no experience with this so I can't add anything useful, but maybe this helps: forums.aws.amazon.com/thread.jspa?threadID=80386 if it doesn't, consider Googling for the error message first, it's more likely to yield a response Commented Dec 2, 2011 at 10:21

1 Answer 1

2

Without having your code to view it's hard to help but here is some example code that you might find helpful:

class myS3Helper{
public function getSignedImageLink($timeout = 1800, $my_aws_secretkey, $my_aws_key)
{

    $now = new Zend_Date(); //Gives us a time object that is set to NOW
    $now->setTimezone('UTC'); //Set to UTC a-la AWS requirements
    $now->addSecond($timeout); //set the time in the time object to a point in the future
    $expirationTime = $now->getTimestamp(); //returns unix timestamp representation of the time.

    $signature = urlencode(
            base64_encode(
                    hash_hmac(
                            'sha1', $this->_generateStringToSign($expirationTime),
                            $my_aws_secretkey, 
                            true
                            )
                    )
            );

    //Yes - this is ugly but hopefully readable 
    $url = 'https://';
    $url .= Zend_Service_Amazon_S3::S3_ENDPOINT; //e.g s3.amazonaws.com
    $url .= $this->_getImagePath(); //e.g /mybucket/myFirstCar.jpg
    $url .='?AWSAccessKeyId=' . $my_aws_key;
    $url .='&Signature=' . $signature; //signature as returned by below function
    $url .='&Expires=' . $expirationTime;

    return $url;


}

protected function _generateStringToSign($expires)
{   

    $string = "GET\n"; //Methods
    $string .= "\n";
    $string .= "\n";
    $string .= "$expires\n"; //Expires
    $string .= $this->_getImagePath();

    return $string;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.