chenhg5/cc-connect · error
media too large: chunks exceeds maximum
Error message
media too large: %d chunks exceeds maximum %d
What it means
uploadWSMedia enforces an upper bound on upload size: the data must fit within wecomWSUploadMaxChunks chunks of wecomWSUploadChunkSize bytes each. Oversized payloads would fail mid-upload after wasting time and bandwidth, so the limit is checked up front and this formatted error reports both the computed chunk count and the maximum allowed.
Solutions
- Check the file size before sending and reject/downscale anything above the limit with a user-friendly message.
- Compress or transcode the media (image re-encode, video bitrate reduction, archive compression) to fit within the limit.
- Split very large files into multiple smaller files, or host externally and send a link instead.
- If the constant is configurable in your build/config, raise wecomWSUploadMaxChunks — but confirm the WeCom server actually accepts larger uploads.
Example fix
// before
if err := p.SendFile(chatID, bigVideo, "recording.mp4"); err != nil { ... }
// after
const maxUpload = wecomWSUploadMaxChunks * wecomWSUploadChunkSize
if len(bigVideo) > maxUpload {
return fmt.Errorf("file is %d bytes; max supported is %d — compress or send a link", len(bigVideo), maxUpload)
}
if err := p.SendFile(chatID, bigVideo, "recording.mp4"); err != nil { ... } Defensive patterns
Strategy: validation
Validate before calling
func withinWSUploadLimit(data []byte) bool {
return len(data) > 0 && len(data) <= wecomWSUploadMaxChunks*wecomWSUploadChunkSize
} Try / catch
var tooLarge *MediaTooLargeError
if errors.As(err, &tooLarge) {
// compress, split, or fall back to sending a download link
} Prevention
- Check file size at intake (before queuing a send) and reject or compress oversized media early.
- Pipeline large videos/archives through a compressor/transcoder sized to wecomWSUploadMaxChunks*wecomWSUploadChunkSize.
- Prefer sending external links for large artifacts instead of raw upload.
- Re-check the limit after library upgrades in case wecomWSUploadMaxChunks changed.
When it happens
Trigger: SendImage or SendFile invoked with data whose size exceeds wecomWSUploadMaxChunks * wecomWSUploadChunkSize — e.g. a multi-hundred-MB video or log archive passed to SendFile over the WebSocket transport.
Common situations: Users forwarding large recorded videos or build artifacts through the bot; deployments where the WeCom WebSocket channel replaces the HTTP upload path that had different (larger) limits; version changes where the WS chunk limit was introduced and previously-working large files started failing.
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
- empty media data
- decode upload init response
- upload init: empty upload_id
- upload init
- wecom: callback_token and callback_aes_key are required
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/29578b9ab236e607.
Report an issue: GitHub.
Appendix: source
Thrown at platform/wecom/websocket_outbound_media.go:50
}
mediaID, err := p.uploadWSMedia(ctx, "image", wsImageFileName(img), img.Data)
if err != nil {
return fmt.Errorf("wecom-ws: send image: %w", err)
}
if err := p.sendWSMediaMessage(ctx, rc.chatID, "image", mediaID); err != nil {
return fmt.Errorf("wecom-ws: send image: %w", err)
}
return nil
}
func (p *WSPlatform) uploadWSMedia(ctx context.Context, mediaType, filename string, data []byte) (string, error) {
totalChunks := (len(data) + wecomWSUploadChunkSize - 1) / wecomWSUploadChunkSize
if totalChunks == 0 {
return "", fmt.Errorf("empty media data")
}
if totalChunks > wecomWSUploadMaxChunks {
return "", fmt.Errorf("media too large: %d chunks exceeds maximum %d", totalChunks, wecomWSUploadMaxChunks)
}
sum := md5.Sum(data)
initReqID := p.generateReqID("aibot_upload_media_init")
initFrame := map[string]any{
"cmd": "aibot_upload_media_init",
"headers": map[string]string{"req_id": initReqID},
"body": map[string]any{
"type": mediaType,
"filename": filename,
"total_size": len(data),
"total_chunks": totalChunks,
"md5": hex.EncodeToString(sum[:]),
},
}
initResp, err := p.writeAndWaitFrameWithTimeout(ctx, initFrame, initReqID, wsMediaAckTimeout)
if err != nil {
return "", fmt.Errorf("upload init: %w", err)View on GitHub (pinned to 4000b2338a)