Problem description
The value of the policy form field in the request header of a PostObject request is not Base64-encoded.
Causes
The policy form field in a PostObject request has an invalid format, which causes a request error.
Examples
None.
Solutions
To construct a valid policy form field:
-
Create a UTF-8-encoded policy.
-
Base64-encode the policy and use the result as the value of the policy form field.
Complete examples:
-
Python
import base64
import json
policy = {
"expiration": "2023-02-19T13:19:00.000Z",
"conditions": [
["content-length-range", 0, 1048576000]
]
}
encoded_policy = base64.b64encode(json.dumps(policy).encode('utf-8'))
-
JavaScript
var policyText = {
"expiration": "2023-02-18T21:39:00.000Z",
"conditions": [
["content-length-range", 0, 1048576000]
]
};
var policyBase64 = Base64.encode(JSON.stringify(policyText))
References
-
For more information, see Appendix: Post Policy.
-
To learn how to upload data from a web client to OSS by using form upload, see Add signatures on the client using JavaScript and upload data to OSS.
-
For common errors and troubleshooting methods of the PostObject operation, see PostObject.
该文章对您有帮助吗?