Question:
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.
I don’t see the problem. 🙁
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
$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')); ?> File to upload to S3: |
I substituted the bucket name as well as the private and public keys above.
I followed the instruction to sign the policy meticulously:
http://docs.amazonwebservices.com/AmazonS3/2006-03-01/dev/HTTPPOSTForms.html#HTTPPOSTConstructPolicy
What am I missing? Why is the code not working?
Answer:
Okay, I finally managed to get this done using this sample code library:
http://aws.amazon.com/code/Amazon-S3/1618