【发布时间】:2018-11-07 11:18:43
【问题描述】:
我正在尝试使用 Policy doument 设置文件上传到谷歌云存储。
参考: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>
【问题讨论】:
-
您能解释一下您将文件上传到存储桶的确切语法是什么吗?将策略文档作为 JSON 文件分发可能会更容易
-
"{'expiration': '2020-06-16T11:11:11Z', '条件': [ ['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] ]}"
-
对不起,我不清楚。我的意思是整个 HTTP 请求使用 POST 方法。
-
我正在使用有问题的 html 表单描述
标签: google-app-engine google-api google-cloud-storage