Skip to main content

Get Upload Certificate

Brief Description

  • Initialize form direct upload task, get temporary URL, fields, and Header needed for upload.

Request Method

  • post

Request URL

  • {API_ADDRESS}/object/initiate_form_data
Header NameExample ValueOptionalTypeDescription
operationID1646445464564RequiredstringUsed for global link tracking, timestamp is recommended, independent in each request
tokeneyJhbxxxx3XsRequiredstringAdmin token

Request Parameter Example

{
"name": "avatar.png",
"size": 204800,
"contentType": "image/png",
"group": "avatar",
"millisecond": 600000
}
Field NameOptionalTypeDescription
nameRequiredstringObject name, usually the file name
sizeRequiredint64File size (bytes)
contentTypeRequiredstringFile MIME type, such as image/png
groupOptionalstringFile group flag, used to distinguish business directories on the storage side
millisecondOptionalint64Valid duration of upload address (milliseconds), leave blank to use server default value

Success Return Example

{
"errCode": 0,
"errMsg": "",
"errDlt": "",
"data": {
"id": "upload-task-id",
"url": "https://storage.example.com/form-upload",
"file": "file",
"header": [
{
"key": "Content-Type",
"value": "multipart/form-data"
}
],
"formData": {
"policy": "BASE64_POLICY",
"signature": "SIGN_VALUE",
"key": "tmp/avatar.png"
},
"expires": 1715065020123,
"successCodes": [
200
]
}
}

Parameter Description for Success Return Example

Parameter NameTypeDescription
errCodeintError code, 0 means success
errMsgstringBrief error message, empty
errDlterrDltDetailed error message, empty
dataobjectGeneric data object, specific structure is below
idstringUpload task ID, used later when calling finish interface
urlstringThird-party storage direct upload address
filestringForm field name corresponding to the file content
headerKeyValues ArrayDirect upload HTTP Header list
formDatamap<string,string>Business field set that needs to be appended in the form
expiresint64Certificate expiration timestamp (milliseconds)
successCodesarray<int32/>Acceptable HTTP status codes when direct upload is successful, such as 200

Upload Instructions

  1. Construct a multipart/form-data request with target address as the returned url.
  2. Add the key-values given in header to the HTTP Header.
  3. Write all key-value pairs of formData into the request body, keep key names and key values original.
  4. Put the real file content into the file field (field name must be consistent with the return value), e.g. -F "file=@avatar.png".
  5. Check whether the upload is successful according to the successCodes list, and call confirm interface after receiving a successful response.

Example Command:

curl -X POST "https://storage.example.com/form-upload" \
-H "Content-Type: multipart/form-data" \
-F "policy=BASE64_POLICY" \
-F "signature=SIGN_VALUE" \
-F "key=tmp/avatar.png" \
-F "file=@avatar.png"