Skip to Content
Developer GuideUpload Policy Description

Instructions for Upload Policy

The US3 upload policy (PutPolicy) is used to complete specified operations while uploading an object. These operations will be triggered and completed after the upload action finishes (some actions are executed before the upload starts).

APIs that can use PutPolicy include: PutFile, FinishMultipartUpload.

US3 Upload Callback

The upload policy can implement callbacks to other services (callback) to process the uploaded file.

This policy specifies that after the file upload is completed (carrying possible parameters), a request is sent to a user-specified service address (currently only HTTP is supported, and only one specified service can be requested). After receiving a response from the user’s server (which must be in application/json format), the return value from the user’s server is passed back to the user. The address of the callback service is encapsulated in 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 carrying an upload policy, the Authorization field in the authorization part is different from that without an upload policy.

Without an upload policy, the format of Authorization during upload is:

Authorization: XXXCloud publickey:signature

When using an upload policy, the format is:

Authorization: XXXCloud publickey:signature:encodedPutPolicy

Where encodedPutPolicy = base64(json_encode(put_policy)) (Note: The JSON format must be compressed without whitespace characters, unless the key/value itself is a string containing whitespace characters. The base64 here is URL-safe base64).

In addition, the signature string calculation method for the old method is:

signstring = HTTP-Verb + "\n" + Content-MD5 + "\n" + Content-Type + "\n" + Date + "\n" + CanonicalizedXXXCloudHeaders + CanonicalizedResource

When an upload request needs to execute an upload policy, other parts of the signature string remain unchanged, but the base64 string of the upload policy must be appended at the end, i.e.:

signstring\_ with\_ putpolicy = signstring + base64(json_encode(put_policy))

Usage Example

If the file to be uploaded is: flower.jpg, and 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 an upload policy:

PUT /flower.jpg HTTP/1.1 Content-Length: 123456 Content-Type: image/jpeg Host: test.ufile.example.cn Authorization: XXXCloud aGVsbHdvZGhhZGhhc2RoYWRzZGFkaHNkaGFkaGhkaGxrc2Rh:bTgzdWhkZGlsYS9kLmFkYWRhc2Ruaw==

Upload request carrying an upload policy:

PUT /flower.jpg HTTP/1.1 Content-Length: 123456 Content-Type: image/jpeg Host: test.ufile.example.cn Authorization: XXXCloud aGVsbHdvZGhhZGhhc2RoYWRzZGFkaHNkaGFkaGhkaGxrc2Rh:ZGFkLHBwMz0xZGthZGFkYXNkYQ==:XCJjYWxsYmFja1VybFwiOlwiIGh0dHA6Ly9pbm5lci51bWVkaWEudWNsb3VkLmNtLmNuL0NyZWF0ZVVtZWRpYVRhc2tcIixcImNhbGxiYWNrQm9keVwiOlwidXJsPWh0dHA6Ly9kZW1vLnVmaWxlLnVjbG91ZC5jbi90ZXN0Lm1wNCYgcGF0dGVuX25hbWU9bXlwb2xpY3lcIg==

Note: The signature is related to the bucket, and the signature in the example is for reference only.