Creating PHP Array - Google Storage - POST - Trouble With Generating Security Policy

Discussion in 'Programming' started by tlshaheen, Dec 26, 2010.

  1. #1
    I believe this problem is PHP - I'm not creating my policy in the correct manner. I am creating the following form for using the POST object with Google Storage to allow a user to upload a document to my bucket. I am getting the following error when I submit the form. I am sure I am creating my policy wrong, but I am unsure how to do it correctly, I've tried several ways. Google's documentation explains the policy here (http://code.google.com/apis/storage/docs/reference-methods.html#postobject). Thank you for your help!

    Their example of a policy is as follows:


    class Policy {
        public $expiration = "2010-12-31T11:11:11Z";
        public $conditions = array("acl" => "private",
                            "failure_action_redirect" => "http://www.example.com/failure_instructions.html");
    }
    $policy = new Policy();
    $policy = json_encode($policy);
    
    $policy_utf = utf8_encode($policy);
    $policy_base64 = base64_encode($policy_utf);
    $policy_sig = base64_encode(hash_hmac('sha1', $policy_base64, $secret, TRUE));
    ?>
    PHP:
    <form action="http://<example_bucket>.commondatastorage.googleapis.com" method="post" enctype="multipart/form-data">
                <input type="hidden" name="key" value="test_documenttttt">
                <input type="hidden" name="GoogleAccessId" value="<?php echo $key; ?>">
                <input type="hidden" name="policy" value="<?php echo $policy_base64; ?>">
                <input type="hidden" name="signature" value="<?php echo $policy_sig; ?>">
                <input type="file" name="file">
                <input type="submit" value="Upload!">
    </form>
    HTML:

     
    tlshaheen, Dec 26, 2010 IP