# uploadFile
Call this API at the server side. For more information, see Server API.
Gets the file upload link
# Request Address
POST https://api.weixin.qq.com/tcb/uploadfile?access_token=ACCESS_TOKEN
# Request Parameters
Attribute | Type | Default | Required | Description |
---|---|---|---|---|
access_token | string | Yes | Credentials to call API | |
env | string | Yes | Cloud environment ID | |
path | string | Yes | Upload path |
# Return Value
# Object
JSON data package that is returned
Attribute | Type | Description |
---|---|---|
errcode | number | Error code |
errmsg | string | Error message |
url | string | Upload URL |
token | string | token |
authorization | string | authorization |
file_id | string | File ID |
cos_file_id | string | cos file ID |
Valid values of errcode
Value | Description | Minimum Version |
---|---|---|
0 | Request successful | |
-1 | System Error | |
-1000 | System Error | |
40014 | Invalid AccessToken | |
40097 | Invalid request parameter | |
40101 | Required parameter missing | |
41001 | AccessToken missing | |
43002 | HTTP METHOD error | |
44002 | Empty POST BODY | |
47001 | Incorrect format of POST BODY | |
85088 | Cloud Base is not enabled on this App | |
Other error codes | Cloud Base error codes |
# Request Data Example
{
"env": "test2-4a89da",
"path": "this/is/a/example/file.path"
}
# Return Data Example
{
"errcode": 0,
"errmsg": "ok",
"url": "https://cos.ap-shanghai.myqcloud.com/7465-test2-4a89da-1258717764/testupload",
"token": "Cukha70zkXIBqkh1OhUIFqjUmXLXeSWq7dff61099221bb270522b8e0cf21d72e0aWCfGXEIDT5bKVJgykFFr9_MeQ-ExrsZ8oiFdMwyYag8h0r-EJq_EaO94KzksxH6bAeb4Y7SwZjJqoy_4g1Na797F1IEG9Dnstm_rz02AgaP5HbJwt1P-XHT4Xjw_lafla079gtQKAP-EPbE5Tc8BRXIm32esjGDDDuDyml7IJqbsPolYZ4-CHQsisdx488loGAN4f7YRMkrrP1Pgi5XOm0-iG5HbWd3tHtuE2pzsGkTobO_fyz2PfSPaeUt_735ll38yIWpAFESAsZnBj2DcRSPBT2FJ_s5mOZACS53q6-tWXPO0AR3-EhOCQpiDKsldVsCxz00Uwhgm1T6Ozw777fJEFkUIngUdZ5yajy3LA84Mpfu6CLkFjfiBtz3wpmcCQxhijo_CrVHkmaMc2JBQ",
"authorization": "q-sign-algorithm=sha1&q-ak=AKID98EDB528Sfqerp0Z_7l23we-u4Avrx04te9VvlzGihMTseysMgu7iSdh_hxEnoAy&q-sign-time=1557307130;1557308030&q-key-time=1557307130;1557308030&q-header-list=&q-url-param-list=&q-signature=ac95227b67a04157bb5e49b435c6ac3ce88e03f2",
"file_id": "cloud://test2-4a89da.7465-test2-4a89da-1258717764/testupload",
"cos_file_id": "HDze32/qZENCwWi5N5akgoXSv3U8DsccKaqCxTMGs0zFgvlD28j484/VYFPJ1l2QDh0Qy8wNbQCpxs5zEsLJln1lIY9RGYn1LzRQQQYFQm+Xwvw6S4YEZN1AIwY906mwIBgiI3gKGkU2K1+1ZEnEYEM4Uh/C1JxB4Q=="
}
# How to Use an Upload Link
After the data is returned, you need to construct a HTTP POST request, where the URL is the URL in the response package, and the format of Body is multipart/form-data, as shown below.
key | value | Description |
---|---|---|
key | this/is/a/example/file.path | path in the request package |
Signature | q-sign-algorithm=sha1&q-ak=AKID9... | authorization in the return data |
x-cos-security-token | Cukha70zkXIBqkh1Oh... | token field in the return data |
x-cos-meta-fileid | HDze32/qZENCwWi5... | cos_file_id in the return data |
file | File content | File content in binary format |