chenhg5/cc-connect · error

wecom: upload image failed: %d %s

Error message

wecom: upload image failed: %d %s

What it means

WeCom API rejection of the media upload: the response decoded as JSON but errcode was non-zero. Frequent causes: 40014/42001 expired access_token attached to the upload URL, 44001 media size exceeded, 45009 rate limiting, or invalid multipart content.

Source

Thrown at platform/wecom/wecom.go:582

		"access_token": []string{accessToken},
		"type":         []string{"image"},
	})
	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)

View on GitHub (pinned to 4000b2338a)

Solutions

  1. On token errors, refresh the access_token and re-upload
  2. On size errors (44001/41059), compress or downscale the image before upload
  3. On 45009, back off and retry later
  4. Log errcode/errmsg (already included) and map to user guidance
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at platform/wecom/wecom.go:582 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/9843fdd22adb4bae. Report an issue: GitHub.