Problem description
A PostObject request fails.
Causes
The policy form field value is not UTF-8-encoded before being Base64-encoded. OSS requires the policy value to be a JSON document encoded as UTF-8 and then Base64.
Examples
After Base64-decoding the request data, the decoded output contains characters that are not valid UTF-8.
Solutions
Encode the policy value in the correct order:
Write the policy as a valid JSON document.
Encode the JSON string as UTF-8.
Base64-encode the UTF-8 bytes.
The policy field declares the conditions a PostObject request must satisfy. OSS uses it to verify request validity.
The following is an example of a valid PostObject request:
POST / 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"
eyJleHBpcmF0aW9uIjoiMjAxMy0xMi0wMVQxMjowMDowMFoiLCJjb25kaXRpb25zIjpbWyJjb250ZW50LWxlbmd0aC1yYW5nZSIsIDAsIDEwNDg1NzYwXSx7ImJ1Y2tldCI6ImFoYWhhIn0sIHsiQSI6ICJhIn0seyJrZXkiOiAiQUJDIn1dfQ==
--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--References
For the
policyfield structure and conditions, see the "Appendix: Policy" section of the PostObject topic.For an end-to-end example of form upload with client-side signature generation, see Add signatures on the client by using JavaScript and upload data to OSS.
For other common PostObject errors and how to resolve them, see PostObject common errors.