0006-00000205

问题描述

PostObject请求头表单中policy表单域值为空。

问题原因

Policy用于验证请求表单域的合法性。不包含policy表单域的请求被认为是匿名请求,即只能访问public-read-writeBucket。如果访问的Bucket为非public-read-write或者提供了OSSAccessKeyId(或Signature)表单域的情况下,policy表单域的值为空,则导致请求报错。

问题示例

以下请求中包含了OSSAccessKeyId以及Signature表单域,但是policy表单域的值(第25行)为空。

OST / HTTP/1.1
Host: oss-example.oss-cn-hangzhou.aliyuncs.com
Content-Length: 344606
Content-Type: multipart/form-data; boundary=9431149156168
--9431149156168
Content-Disposition: form-data; name="key"
/user/a/objectName.txt
--9431149156168
Content-Disposition: form-data; name="success_action_status"
200
--9431149156168
Content-Disposition: form-data; name="Content-Disposition"
content_disposition
--9431149156168
Content-Disposition: form-data; name="x-oss-meta-uuid"
uuid
--9431149156168
Content-Disposition: form-data; name="x-oss-meta-tag"
metadata
--9431149156168
Content-Disposition: form-data; name="OSSAccessKeyId"
44CF9590006BF252****
--9431149156168
Content-Disposition: form-data; name="policy"

--9431149156168
Content-Disposition: form-data; name="Signature"
kZoYNv66bsmc10+dcGKw5x2P****
--9431149156168
Content-Disposition: form-data; name="file"; filename="MyFilename.txt"
Content-Type: text/plain
abcdefg
--9431149156168
Content-Disposition: form-data; name="submit"
Upload to OSS
--9431149156168--

解决方案

确保PostObject请求中policy表单域的值不为空且正确无误。您可以参考以下步骤构建Policy表单域的值。

  1. 创建一个UTF-8编码的policy。

  2. policy进行Base64编码,其值即为policy表单域填入的值。

完整示例如下:

  • Python

policy = {
    "expiration": "2023-02-19T13:19:00.000Z",
    "conditions": [
        ["content-length-range",  0, 1048576000]
    ]
}
encoded_policy = base64.b64encode((json.dumps(policy))
  • JavaScript

var policyText = {
    "expiration": "2023-02-18T21:39:00.000Z",
    "conditions": [
    	["content-length-range",  0, 1048576000]
    ]
};

var policyBase64 = Base64.encode(JSON.stringify(policyText))

相关文档