Problem description
A PostObject request fails because a value in the conditions array of the policy form field has an invalid data type.
Causes
Each condition in the conditions array is a tuple that starts with an operator, followed by operator-specific fields and values. The data type of the value must match what the operator requires. The in and not-in operators require a List (a JSON array) as the value, not a String.
Examples
The following policy triggers the error. The not-in operator receives "no-cache" as a String, but it requires a List:
{
"expiration": "2023-02-19T13:19:00.000Z",
"conditions": [
["not-in", "cache-control", "no-cache"]
]
}Solutions
Pass the correct data type for each operator. The following table shows the required value type for each operator used in the examples below:
| Operator | Required value type | Example |
|---|---|---|
eq | String | ["eq", "$success_action_status", "201"] |
starts-with | String | ["starts-with", "$key", "user/eric/"] |
content-length-range | Two integers (min, max) | ["content-length-range", 1, 1024] |
in | List | ["in", "$content-type", ["image/jpeg", "image/png"]] |
not-in | List | ["not-in", "$cache-control", ["no-cache"]] |
The following example shows a valid conditions array using all supported operators:
{
"expiration": "2023-02-19T13:19:00.000Z",
"conditions": [
["content-length-range", 1, 1024],
["eq", "$success_action_status", "201"],
["starts-with", "$key", "user/eric/"],
["in", "$content-type", ["image/jpeg", "image/png"]],
["not-in", "$cache-control", ["no-cache"]]
]
}References
For the full
policyfield specification, see the "Appendix: Policy" section of PostObject.To upload objects from a web client using form upload, see Add signatures on the client by using JavaScript and upload data to OSS.
For other common PostObject errors, see PostObject.