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
policyvalue is not valid Base64-encoded UTF-8 JSON, or the JSON is missing the required top-level fields (expirationandconditions).Policy condition mismatch: The
policyis 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 OSSNote:OSSAccessKeyId,policy, andSignatureare interdependent. If you includeOSSAccessKeyId, you must also include bothpolicyandSignature.
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
expirationandconditions. Both fields are required — omitting either causes the request to fail.expirationis 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, andSignature) appears inconditions.
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 field | Example value | Must match |
|---|---|---|
key | /user/a/objectName.txt | Exact value or starts-with condition |
success_action_status | 200 | Exact value condition |
Content-Disposition | content_disposition | Exact value or starts-with condition |
x-oss-meta-uuid | uuid | Exact value or starts-with condition |
x-oss-meta-tag | metadata | Exact value or starts-with condition |
OSS supports three condition matching types:
| Type | Syntax | Example |
|---|---|---|
| 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
Appendix: Policy — full reference for the policy field structure and condition syntax
Add signatures on the client by using JavaScript and upload data to OSS — end-to-end example for web client uploads
Errors and troubleshooting methods of PostObject — complete list of PostObject error codes and fixes