我正在创建以下表单,以便将POST对象与Google Storage一起使用,以允许用户将文档上传到我的存储桶。我提交表单时收到以下错误。我确信我的政策是错误的,但我不确定如何正确地做到这一点,我尝试了几种方法。 Google's documentation explains the policy here。谢谢你的帮助!
<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>
答案 0 :(得分:1)
解决!
这就像教程所做的那样简单 - 我对它的研究太多了。只需设置$policy = <the code>
和UTF-8即可对其进行编码。我的问题是我会设置$policy = <the example code>
,但后来我会json_encode()。它已经被JSON
编码,所以JSON编码搞砸了。我也读错了
很多!
$policy = '{ "expiration": "2010-12-31T11:11:11Z",'.
'"conditions": ['.
'["starts-with", "$key", "" ],'.
'{"acl": "private" }'.
']'.
'}';