Skip to main content

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.

ItemDescription
URLhttps://api-coco.typex.im/open/robot/upload
MethodPOST
Content-Typemultipart/form-data

Request Headers

Authorization: Bearer <bot_token>
Content-Type: multipart/form-data

Request Parameters

ParameterTypeRequiredDescription
chat_idstringYesConversation ID
file_namestringYesFile name
file_typestringYesFile type: image / audio / video / application
file_contentfileYesFile 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"
}
FieldDescription
data.objectKeyUnique resource identifier, used for download
data.addressResource access URL
data.widthImage width (returned for image type only)
data.heightImage 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

ItemDescription
URLhttps://api-coco.typex.im/open/robot/chat/file
MethodGET

Request Headers

Authorization: Bearer <bot_token>

Request Parameters

ParameterTypeRequiredDescription
object_keystringYesThe 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'