{"record":{"id":"29578b9ab236e607","repo":"chenhg5/cc-connect","slug":"media-too-large-d-chunks-exceeds-maximum-d","errorCode":null,"errorMessage":"media too large: %d chunks exceeds maximum %d","messagePattern":"media too large: (.+?) chunks exceeds maximum (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"platform/wecom/websocket_outbound_media.go","lineNumber":50,"sourceCode":"\t}\n\n\tmediaID, err := p.uploadWSMedia(ctx, \"image\", wsImageFileName(img), img.Data)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"wecom-ws: send image: %w\", err)\n\t}\n\tif err := p.sendWSMediaMessage(ctx, rc.chatID, \"image\", mediaID); err != nil {\n\t\treturn fmt.Errorf(\"wecom-ws: send image: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (p *WSPlatform) uploadWSMedia(ctx context.Context, mediaType, filename string, data []byte) (string, error) {\n\ttotalChunks := (len(data) + wecomWSUploadChunkSize - 1) / wecomWSUploadChunkSize\n\tif totalChunks == 0 {\n\t\treturn \"\", fmt.Errorf(\"empty media data\")\n\t}\n\tif totalChunks > wecomWSUploadMaxChunks {\n\t\treturn \"\", fmt.Errorf(\"media too large: %d chunks exceeds maximum %d\", totalChunks, wecomWSUploadMaxChunks)\n\t}\n\n\tsum := md5.Sum(data)\n\tinitReqID := p.generateReqID(\"aibot_upload_media_init\")\n\tinitFrame := map[string]any{\n\t\t\"cmd\":     \"aibot_upload_media_init\",\n\t\t\"headers\": map[string]string{\"req_id\": initReqID},\n\t\t\"body\": map[string]any{\n\t\t\t\"type\":         mediaType,\n\t\t\t\"filename\":     filename,\n\t\t\t\"total_size\":   len(data),\n\t\t\t\"total_chunks\": totalChunks,\n\t\t\t\"md5\":          hex.EncodeToString(sum[:]),\n\t\t},\n\t}\n\tinitResp, err := p.writeAndWaitFrameWithTimeout(ctx, initFrame, initReqID, wsMediaAckTimeout)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"upload init: %w\", err)","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/platform/wecom/websocket_outbound_media.go#L32-L68","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nif err := p.SendFile(chatID, bigVideo, \"recording.mp4\"); err != nil { ... }\n\n// after\nconst maxUpload = wecomWSUploadMaxChunks * wecomWSUploadChunkSize\nif len(bigVideo) > maxUpload {\n    return fmt.Errorf(\"file is %d bytes; max supported is %d — compress or send a link\", len(bigVideo), maxUpload)\n}\nif err := p.SendFile(chatID, bigVideo, \"recording.mp4\"); err != nil { ... }","handlingStrategy":"validation","validationCode":"func withinWSUploadLimit(data []byte) bool {\n    return len(data) > 0 && len(data) <= wecomWSUploadMaxChunks*wecomWSUploadChunkSize\n}","typeGuard":null,"tryCatchPattern":"var tooLarge *MediaTooLargeError\nif errors.As(err, &tooLarge) {\n    // compress, split, or fall back to sending a download link\n}","preventionTips":["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."],"tags":["wecom","media-upload","file-size-limit","validation"],"backgroundTag":"file-size-limit-exceeded","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}