Media never travels over the WebSocket. Upload the file over HTTPS first, then send the id you get back in a message.
💡 Every SDK ships a
MediaTransferhelper that does the whole PUT for you. Reach for the raw HTTP below only if you need the query parameters or you are not using an SDK.
| SDK | Call |
|---|---|
| Java | String fileId = MediaTransfer.uploadFile(token, "./upload/photo.jpg"); |
| JavaScript | const fileId = MediaTransfer.uploadFile(token, "./upload/photo.jpg", uploadServerURL); |
| Python | file_id = MediaTransfer.upload_file(token, "./upload/photo.jpg", upload_server_url) |
Pass the returned id to sendPhoto, sendVideo, sendDocument, and so on.
PUT https://<nandboxMediaServer>:<port>/nandbox/upload/<FileName>
For example: https://w1.nandbox.net:8080/nandbox/upload/photo.jpg
| Header | Value |
|---|---|
Content-Type |
The file's MIME type. Must be correct — the server classifies the media by it. |
X-Token |
Your bot token. |
| Parameter | Description |
|---|---|
p |
1 makes the upload public and returns a download link. |
cache |
1 returns size, width, height, and a thumbnail. Only meaningful when p=1. |
The raw binary content of the file.
The server decides what kind of media you uploaded from the Content-Type header.
| Media Type | Content Type (MIME Type) |
|---|---|
| Text File | text/plain |
| Image | image/jpeg, image/png, multipart/form-data |
| GIF Image | image/gif |
| Audio | audio/midi, audio/mp4, audio/mpeg, audio/ogg, audio/basic |
| Video | video/mp4, video/mpeg, video/ogg |
| File (documents & archives) | application/zip, application/pdf, application/msword, application/vnd.openxmlformats-officedocument.wordprocessingml.document, application/x-tar, application/x-7z-compressed, application/x-zip-compressed, application/x-rar-compressed, application/vnd.android.package-archive, application/vnd.ms-excel |
multipart/form-data is treated as an image upload.