Upload Process
1. Upload File Parts
Usemedia.uploadFilePart to upload file data in chunks:
Unique identifier for this upload session, generated by the client
Sequential part number (0-indexed)
Binary data for this part
Upload Flow
- Generate upload ID: Create a unique
upload_idon the client - Split file: Divide the file into chunks
- Upload parts: Send each part with
media.uploadFilePart - Track parts: Keep track of uploaded parts (0, 1, 2, …)
- Get reference: After all parts are uploaded, you’ll receive an
UploadedFileRef
UploadedFileRef
After uploading all parts, you’ll receive anUploadedFileRef to reference the uploaded file:
Server-assigned file identifier
File name
Total number of parts uploaded
Using Uploaded Files
To attach an uploaded file to a message, wrap it inMediaRefUploadedFile:
Reference to the uploaded file
Optional filename override
MIME type (e.g.,
image/jpeg, video/mp4)MediaRef
TheMediaRef type allows referencing either an uploaded file or an embed:
Example: Attaching to Message
Best Practices
- Chunk size: Use 256 KB - 1 MB chunks for optimal performance
- Retry logic: Implement retry for failed part uploads
- Progress tracking: Track upload progress by monitoring completed parts
- Concurrent uploads: Upload multiple parts in parallel (with rate limiting)
- Metadata: Always include appropriate metadata for the file type