chenhg5/cc-connect · error
wecom: upload image: empty media_id
Error message
wecom: upload image: empty media_id
What it means
Inconsistency guard after a successful image upload: WeCom returned errcode 0 but an empty media_id, leaving nothing to reference in the subsequent message/send. The API contract promises a media_id on success, so this indicates a malformed success response or an API-side change.
Source
Thrown at platform/wecom/wecom.go:585
resp, err := p.apiClient.Post(apiURL, writer.FormDataContentType(), body)
if err != nil {
return "", fmt.Errorf("wecom: upload image: %w", err)
}
defer resp.Body.Close()
var result struct {
ErrCode int `json:"errcode"`
ErrMsg string `json:"errmsg"`
MediaID string `json:"media_id"`
}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return "", fmt.Errorf("wecom: decode upload response: %w", err)
}
if result.ErrCode != 0 {
return "", fmt.Errorf("wecom: upload image failed: %d %s", result.ErrCode, result.ErrMsg)
}
if result.MediaID == "" {
return "", fmt.Errorf("wecom: upload image: empty media_id")
}
return result.MediaID, nil
}
var _ core.ImageSender = (*Platform)(nil)
func (p *Platform) sendMarkdown(accessToken, toUser, content string) error {
payload := map[string]any{
"touser": toUser,
"msgtype": "markdown",
"agentid": p.agentID,
"markdown": map[string]string{"content": content},
}
body, _ := json.Marshal(payload)
apiURL := p.wecomAPIURL("/cgi-bin/message/send", url.Values{
"access_token": []string{accessToken},
})View on GitHub (pinned to 4000b2338a)
Solutions
- Retry the upload once — transient malformed responses do occur
- If persistent, capture the full response body and check WeCom API docs for contract changes
- Fail the image send gracefully with a text fallback message instead of leaking the internal error
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at platform/wecom/wecom.go:585 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/008aef8429376eb1.
Report an issue: GitHub.