Problem description
When you call the PostObject operation to upload an object, the upload fails because the object size does not meet the requirements specified in the policy form field.
Causes
The policy form field contains a content-length-range condition that specifies an invalid size range. The content-length-range condition takes two values in bytes: ["content-length-range", <minimum>, <maximum>]. If the object size falls outside this range, OSS rejects the upload.
Examples
The following example attempts to upload small.img. The policy specifies a content-length-range condition that the file does not meet.
Request:
POST / HTTP/1.1
Host: oss-example.oss-cn-hangzhou.aliyuncs.com
Content-Length: 6443500495
Date: Sat, 18 Feb 2023 05:17:02 GMT
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryW0DET1iaBMeAOBg3
Host: example-bucket.oss-cn-hangzhou.aliyuncs.com
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="name"
small.img
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="key"
${filename}
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="policy"
eyJleHBpcmF0aW9uIjoiMjAyMy0wMi0xOFQxMzoxOTowMC4wMDBaIiwiY29uZGl0aW9ucyI6W1siY29udGVudC1sZW5ndGgtcmFuZ2UiLDEwMDg1NzYwMDAsMTA0ODU3NjAwMF1dfQ==
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="OSSAccessKeyId"
LTAI****************
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="success_action_status"
200
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="signature"
miAoLVohS5*****WEXyC3wVecaQ=
------WebKitFormBoundaryW0DET1iaBMeAOBg3
Content-Disposition: form-data; name="file"; filename="small.img"
Content-Type: application/octet-stream
***
------WebKitFormBoundaryW0DET1iaBMeAOBg3--Decoded policy:
{
"expiration": "2023-02-18T13:19:00.000Z",
"conditions": [
["content-length-range", 1008576000, 1048576000]
]
}The policy requires the object to be between 1,008,576,000 bytes and 1,048,576,000 bytes. The small.img file is smaller than the minimum of 1,008,576,000 bytes, so OSS rejects the upload.
Solutions
Make sure the size of the object you want to upload falls within the range specified by content-length-range in the policy form field. The condition takes two values in bytes: minimum and maximum.
Check the actual size of the object in bytes.
Update
content-length-rangeso the minimum value is less than or equal to the object size, and the maximum value is greater than or equal to the object size.
Example — allow objects between 1 MiB and 10 MiB:
{
"expiration": "2023-02-18T13:19:00.000Z",
"conditions": [
["content-length-range", 1048576, 10485760]
]
}Note: Both values are in bytes.1048576= 1 MiB,10485760= 10 MiB.
References
For more information about the PostObject operation, see PostObject.
For information about how to transfer data from a web client to OSS by using form upload, see Add signatures on the client by using JavaScript and upload data to OSS.
For information about common errors and troubleshooting methods of the PostObject operation, see Errors and troubleshooting methods of PostObject.