我正在创建以下表单,以便将 POST 对象与 Google Storage 一起使用,以允许用户将文档上传到我的存储桶。提交表单时出现以下错误。我确定我创建的策略是错误的,但我不确定如何正确执行,我尝试了几种方法。Google 的文档在此处解释了该政策。谢谢您的帮助!
<Error>
<Code>InvalidPolicyDocument</Code> − <Message> The content of the form does not meet the conditions specified in the policy document. </Message>
− <Details> Invalid value for conditions: {"acl":"private","failure_action_redirect":"http:\/\/www.example.com\/failure_instructions.html"} </Details>
</Error>
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));
?>
<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>