File Upload & Download
To send images, audio, video, or files, you typically need to upload the resource first and then reference the upload result when sending the message.
Upload
Endpoint
Upload a file to the TypeX server. On success, returns a resource URL that can be used for subsequent message sending.
| Item | Description |
|---|---|
| URL | https://api-coco.typex.im/open/robot/upload |
| Method | POST |
| Content-Type | multipart/form-data |
Request Headers
Authorization: Bearer <bot_token>
Content-Type: multipart/form-data
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
chat_id | string | Yes | Conversation ID |
file_name | string | Yes | File name |
file_type | string | Yes | File type: image / audio / video / application |
file_content | file | Yes | File content, uploaded as multipart/form-data |
Response Format
{
"code": 0,
"data": {
"objectKey": "image/e2/e2f0069312cd5548",
"address": "https://api-coco.typex.im/chat/get/image/e2/e2f0069312cd5548/1",
"width": 1080,
"height": 719
},
"msg": "ok"
}
| Field | Description |
|---|---|
data.objectKey | Unique resource identifier, used for download |
data.address | Resource access URL |
data.width | Image width (returned for image type only) |
data.height | Image height (returned for image type only) |
Upload Examples
Upload Image
curl --location 'https://api-coco.typex.im/open/robot/upload' \
--header 'Authorization: Bearer <bot_token>' \
--form 'chat_id="7602566729281049630"' \
--form 'file_name="test_image"' \
--form 'file_type="image"' \
--form 'file_content=@"example.png"'
Upload File
curl --location 'https://api-coco.typex.im/open/robot/upload' \
--header 'Authorization: Bearer <bot_token>' \
--form 'chat_id="7602566729281049630"' \
--form 'file_name="test_file"' \
--form 'file_type="application"' \
--form 'file_content=@"example.zip"'
Upload Audio
curl --location 'https://api-coco.typex.im/open/robot/upload' \
--header 'Authorization: Bearer <bot_token>' \
--form 'chat_id="7602566729281049630"' \
--form 'file_name="test_voice"' \
--form 'file_type="audio"' \
--form 'file_content=@"example.wav"'
Upload Video
curl --location 'https://api-coco.typex.im/open/robot/upload' \
--header 'Authorization: Bearer <bot_token>' \
--form 'chat_id="7602566729281049630"' \
--form 'file_name="test_video"' \
--form 'file_type="video"' \
--form 'file_content=@"example.mp4"'
Downloading Files from Callbacks
If a callback contains a file resource URL, use the following endpoint to download it.
Endpoint
| Item | Description |
|---|---|
| URL | https://api-coco.typex.im/open/robot/chat/file |
| Method | GET |
Request Headers
Authorization: Bearer <bot_token>
Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
object_key | string | Yes | The objectKey returned from upload |
Example
curl -G 'https://api-coco.typex.im/open/robot/chat/file' \
-H 'Authorization: Bearer <bot_token>' \
--data-urlencode 'object_key=image/e2/e2f0069312cd5548'