【问题标题】:Policy document parsing error: Lexical Error: Unmatched Input: <'>策略文档解析错误:词法错误:不匹配的输入:<'>
【发布时间】: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: &lt;'&gt;</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


【解决方案1】:

我查看了 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] ]}"

尽管如此,正确的版本应该将所有单撇号替换为双撇号(" 而不是 ')。

{
    "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 表单,它确实会抛出一个不正确的键错误,这意味着不平衡的语句已经解决。你能验证它是否适合你吗?

【讨论】:

  • 是的,它解决了这个问题。但是'" 都应该可以工作。
猜你喜欢
  • 1970-01-01
  • 2014-08-13
  • 1970-01-01
  • 2022-10-13
  • 1970-01-01
  • 2023-01-12
  • 1970-01-01
  • 2018-02-19
  • 2011-09-05
相关资源
最近更新 更多