0006-00000201

更新时间:
复制 MD 格式

Problem description

A PostObject request fails because the policy form field contains an invalid value.

Causes

The policy field can fail for two distinct reasons:

  • Policy syntax error: The policy value is not valid Base64-encoded UTF-8 JSON, or the JSON is missing the required top-level fields (expiration and conditions).

  • Policy condition mismatch: The policy is syntactically valid, but one or more form fields in the request do not satisfy the conditions declared in the policy (for example, the object key does not match the required prefix, or the file size exceeds the allowed range).

Identify which type applies before troubleshooting.

Examples

The following is an example of a valid PostObject request with a correctly constructed policy field.

Plaintext policy (before Base64 encoding):

{
  "expiration": "2013-12-01T12:00:00Z",
  "conditions": [
    ["content-length-range", 0, 10485760],
    {"bucket": "ahaha"},
    {"A": "a"},
    {"key": "ABC"}
  ]
}

The policy field value is the Base64-encoded form of the JSON above:

eyJleHBpcmF0aW9uIjoiMjAxMy0xMi0wMVQxMjowMDowMFoiLCJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDEwNDg1NzYwXSx7ImJ1Y2tldCI6ImFoYWhhIn0sIHsiQSI6ICJhIn0seyJrZXkiOiAiQUJDIn1dfQ==

Full PostObject request:

Host: oss-example.oss-cn-hangzhou.aliyuncs.com
Content-Length: 344606
Content-Type: multipart/form-data; boundary=9431149156168

key: /user/a/objectName.txt
success_action_status: 200
Content-Disposition: content_disposition
x-oss-meta-uuid: uuid
x-oss-meta-tag: metadata
OSSAccessKeyId: 44CF9590006BF252****
policy: eyJleHBpcmF0aW9uIjoiMjAxMy0xMi0wMVQxMjowMDowMFoiLCJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDEwNDg1NzYwXSx7ImJ1Y2tldCI6ImFoYWhhIn0sIHsiQSI6ICJhIn0seyJrZXkiOiAiQUJDIn1dfQ==
Signature: kZoYNv66bsmc10+dcGKw5x2P****
file filename: MyFilename.txt
file Content-Type: text/plain
file content: abcdefg
submit: Upload to OSS
Note: OSSAccessKeyId, policy, and Signature are interdependent. If you include OSSAccessKeyId, you must also include both policy and Signature.

Solutions

Step 1: Decode and inspect your policy.

Convert the Base64 value back to plaintext JSON and verify:

  • The JSON is valid (no syntax errors, no missing brackets).

  • The top-level structure contains both expiration and conditions. Both fields are required — omitting either causes the request to fail.

  • expiration is a valid ISO 8601 UTC timestamp (for example, "2013-12-01T12:00:00Z") and has not passed.

  • Every form field in your request (except file, policy, OSSAccessKeyId, and Signature) appears in conditions.

Step 2: Verify each condition matches the request.

Compare the conditions in your decoded policy against the actual form field values in your request:

Form fieldExample valueMust match
key/user/a/objectName.txtExact value or starts-with condition
success_action_status200Exact value condition
Content-Dispositioncontent_dispositionExact value or starts-with condition
x-oss-meta-uuiduuidExact value or starts-with condition
x-oss-meta-tagmetadataExact value or starts-with condition

OSS supports three condition matching types:

TypeSyntaxExample
Exact match{"field": "value"}{"bucket": "my-bucket"}
Starts with["starts-with", "$field", "prefix"]["starts-with", "$key", "user/"]
Content length range["content-length-range", min, max]["content-length-range", 0, 10485760]

Step 3: Re-encode and resubmit.

After correcting the JSON, re-encode it to UTF-8 Base64 and update the policy field in your request.

References