代码之家  ›  专栏  ›  技术社区  ›  bhavin jalodara

策略文档分析错误:词汇错误:不匹配的输入:<'>

  •  0
  • bhavin jalodara  · 技术社区  · 6 年前

    我正在尝试使用策略文档将文件上传到谷歌云存储。

    裁判: 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>
    
    1 回复  |  直到 5 年前
        1
  •  0
  •   Ggrimaldo    6 年前

    我查看了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表单,它就会给我一个错误的键错误,这意味着不平衡的语句已经被解决了。你能证实它是否适合你吗?