Upload Policy Description
The US3 upload policy (PutPolicy) is used to complete some specified operations while uploading objects. These operations will be triggered and completed after the upload action is completed (some actions are executed before the start of the upload).
APIs that can use PutPolicy include: PutFile, FinishMultipartUpload.
US3 Upload Callback
The upload policy can implement a callback to other services (callback) to process the uploaded file.
This policy specifies that after the file upload is completed (carrying possible parameters), request a user-defined service address (currently only http is supported, and only one specified service request is supported). After receiving the response from the user’s server (must be in application/json format), the return value from the user’s server is transparently delivered to the user. The address of the callback service is encapsulated in the json format, as follows:
{
"callbackUrl" : "http://test.example.cn", // The designated callback service address
"callbackBody" : "key1=value1&key2=value2" // The parameters passed to the callback service
}
For API requests with an upload policy, the Authorization field part differs from those without an upload policy.
Without upload policy, the format of Authorization during upload is:
Authorization: UCloud Global publickey:signature
Using upload policy, the format is:
Authorization: UCloud Global publickey:signature:encodedPutPolicy
Here, encodedPutPolicy = base64(json_ encode(put_ policy)) (Note: Use the compressed format for json. Do not carry white space characters, unless the key/value is a string containing white space characters. The base64 here is URLSafe base64)
In addition, the calculation method of the signature string in the old way is:
signstring = HTTP-Verb + "\n" +
Content-MD5 + "\n" +
Content-Type + "\n" +
Date + "\n" +
CanonicalizedUCloud GlobalHeaders +
CanonicalizedResource
When the upload request needs to execute the upload policy, other parts of the signature string remain unchanged, and the base64 string of the upload policy needs to be appended at the end, i.e.:
signstring\_ with\_ putpolicy = signstring + base64(json_encode(put_policy))
Usage Example
If the uploaded file is: flower.jpg, the upload policy is:
"callbackUrl" : "<http://inner.umedia.example.com.cn/CreateUmediaTask>",
"callbackBody" :"url=<http://demo.ufile.****.cn/flower.jpg&patten_name=mypolicy>"
Upload request without upload policy:
PUT /flower.jpg HTTP/1.1
Content-Length: 123456
Content-Type: image/jpeg
Host: test.ufile.example.cn
Authorization: UCloud Global aGVsbHdvZGhhZGhhc2RoYWRzZGFkaHNkaGFkaGhkaGxrc2Rh:bTgzdWhkZGlsYS9kLmFkYWRhc2Ruaw==
Upload request with upload policy:
PUT /flower.jpg HTTP/1.1
Content-Length: 123456
Content-Type: image/jpeg
Host: test.ufile.example.cn
Authorization: UCloud Global aGVsbHdvZGhhZGhhc2RoYWRzZGFkaHNkaGFkaGhkaGxrc2Rh:ZGFkLHBwMz0xZGthZGFkYXNkYQ==:XCJjYWxsYmFja1VybFwiOlwiIGh0dHA6Ly9pbm5lci51bWVkaWEudWNsb3VkLmNtLmNuL0NyZWF0ZVVtZWRpYVRhc2tcIixcImNhbGxiYWNrQm9keVwiOlwidXJsPWh0dHA6Ly9kZW1vLnVmaWxlLnVjbG91ZC5jbi90ZXN0Lm1wNCYgcGF0dGVuX25hbWU9bXlwb2xpY3lcIg==
Note: The signature is related to the bucket, the signature in the example is for reference only.