我正在尝试使用Policy doument设置文件上传到Google云端存储。
参考:https://cloud.google.com/storage/docs/xml-api/post-object#policydocument
政策文件
{"expiration": "2020-06-16T11:11:11Z",
"conditions": [
["starts-with", "$key", "" ],
{"acl": "bucket-owner-read" },
{"bucket": "cli201509.appspot.com"},
{"success_action_redirect": "http://cli201509.appspot.com/getpolicydocumentsuccess" },
["eq", "$Content-Type", "image/jpeg" ],
["content-length-range", 0, 1000000]
]
}
HTML表格
<form action="http://storage.googleapis.com" method="post" enctype="multipart/form-data">
<input type="text" name="key" value="cli201509.appspot.com/texst/textasad.jpg">
<input type="hidden" name="bucket" value="cli201509.appspot.com">
<input type="hidden" name="Content-Type" value="image/jpeg">
<input type="hidden" name="GoogleAccessId" value="cli201509@appspot.gserviceaccount.com">
<input type="hidden" name="acl" value="bucket-owner-read">
<input type="hidden" name="success_action_redirect" value="http://cli201509.appspot.com/getpolicydocumentsuccess">
<input type="hidden" name="policy" value="eydjb25kaXRpb25zJzogW1snc3RhcnRzLXdpdGgnLCAnJGtleScsICcnXSwgeydhY2wnOiAnYnVja2V0LW93bmVyLXJlYWQnfSwgeydidWNrZXQnOiAnY2xpMjAxNTA5LmFwcHNwb3QuY29tJ30sIHsnc3VjY2Vzc19hY3Rpb25fcmVkaXJlY3QnOiAnaHR0cDovL2NsaTIwMTUwOS5hcHBzcG90LmNvbS9nZXRwb2xpY3lkb2N1bWVudHN1Y2Nlc3MnfSwgWydlcScsICckQ29udGVudC1UeXBlJywgJ2ltYWdlL2pwZWcnXSwgWydjb250ZW50LWxlbmd0aC1yYW5nZScsIDAsIDEwMDAwMDBdXSwgJ2V4cGlyYXRpb24nOiAnMjAyMC0wNi0xNlQxMToxMToxMVonfQ==">
<input type="hidden" name="signature" value="I+jU4464Q7MxYQLl3qeRmrMi98VV5heiYnLMUYhb71Z3aozvwkLU3lfnatg0VAi3/plaQXF3hW93qMduodZ2e3NjRpOW9AYNMs611y2GMGinzEuLtu7h88n5In4ZhNHyOS4jM/xs+ITy1izILjTDHk0JTq1RE2Wb3MXaTWwTjHpwC97YQuTZTBfGEPUwz0tHP21eVlUX+NuC7FpWttskJJ2hheV5yUe0a8PCDYL6WXWlTgKpDbtH0ceMuJJUlVaxH4HN7vC7azes7xRYxgdkeOsrbgRpVbCCgeJQQwcogRk/ZVV1DGS7h6DNAAid69WknrmCNI+KAgLprKXavFQ/uA==">
<input name="file" type="file">
<input type="submit" value="Upload">
</form>
错误回复
<Error><Code>InvalidPolicyDocument</Code>
<Message>The content of the form does not meet the conditions specified in the policy document.</Message>
<Details>Policy document parsing error: Lexical Error: Unmatched Input: <'></Details>
</Error>
答案 0 :(得分:0)
我已经查看了JSON,但我发现它格式不正确。
这是你正在使用的那个,
"{'expiration': '2020-06-16T11:11:11Z', 'conditions': [ ['starts-with', '$key', '' ], {'acl': 'bucket-owner-read' }, {'bucket': 'cli201509.appspot.com'}, {'success_action_redirect':'cli201509.appspot.com/getpolicydocumentsuccess'; }, ['eq', '$Content-Type', 'image/jpeg' ], ['content-length-range', 0, 1000000] ]}"
尽管如此,正确的版本应该将所有单个撇号替换为double(“而不是”)。
{
"conditions": [
["starts-with", "$key", ""], {
"acl": "bucket-owner-read"
}, {
"bucket": "cli201509.appspot.com"
}, {
"success_action_redirect": "http://cli201509.appspot.com/getpolicydocumentsuccess"
},
["eq", "$Content-Type", "image/jpeg"],
["content-length-range", 0, 1000000]
],
"expiration": "2020-06-16T11:11:11Z"
}
一旦我执行HTML表单,它就会给我一个错误的键错误,这意味着不平衡的语句已经解决了。你能证实它是否适合你吗?