chenhg5/cc-connect · error

%s: upload image code=%d msg=%s

Error message

%s: upload image code=%d msg=%s

What it means

The Feishu image upload API returned a response, but the response was not successful (uploadResp.Success() is false), i.e. Feishu returned a business error code and message. The library formats the API's code and msg fields so the caller can see exactly which Feishu-side error occurred.

Source

Thrown at platform/feishu/feishu.go:3297

}

func (p *Platform) uploadImageKey(ctx context.Context, data []byte) (string, error) {
	var uploadResp *larkim.CreateImageResp
	if err := p.withTransientRetry(ctx, "upload image", func() error {
		return p.withFreshTenantAccessTokenRetry(ctx, "upload image", func(client *lark.Client, options ...larkcore.RequestOptionFunc) error {
			req := larkim.NewCreateImageReqBuilder().
				Body(larkim.NewCreateImageReqBodyBuilder().
					ImageType("message").
					Image(bytes.NewReader(data)).
					Build()).
				Build()
			var err error
			uploadResp, err = client.Im.Image.Create(ctx, req, options...)
			if err != nil {
				return fmt.Errorf("%s: upload image: %w", p.tag(), err)
			}
			if !uploadResp.Success() {
				return fmt.Errorf("%s: upload image code=%d msg=%s", p.tag(), uploadResp.Code, uploadResp.Msg)
			}
			return nil
		})
	}); err != nil {
		return "", err
	}
	if uploadResp.Data == nil || uploadResp.Data.ImageKey == nil {
		return "", fmt.Errorf("%s: upload image: no image_key returned", p.tag())
	}

	return *uploadResp.Data.ImageKey, nil
}

func (p *Platform) SendFile(ctx context.Context, rctx any, file core.FileAttachment) error {
	rc, ok := rctx.(replyContext)
	if !ok {
		return fmt.Errorf("%s: SendFile: invalid reply context type %T", p.tag(), rctx)
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Read the code=%d msg=%s values and look them up in Feishu's error code documentation.
  2. Grant the app the im:resource permission and publish/enable the permission version.
  3. Validate the image bytes (format, size under Feishu's limits) before upload.
  4. Retry with backoff if the code indicates throttling (e.g. 1254xxx).
Defensive patterns

Strategy: try-catch

Validate before calling

// Check permission scope before sending:
// app must have im:resource enabled in Feishu open console

Try / catch

if err != nil {
    var respErr *larkcore.APIError
    if errors.As(err, &respErr) && respErr.Code == 99991663 {
        // refresh token / fix credentials
    }
    return err
}

Prevention

When it happens

Trigger: client.Im.Image.Create completes without transport error but uploadResp.Success() is false at platform/feishu/feishu.go:3297 — e.g. code 99991663/99991661 (token invalid), 230001 (invalid image file), or 1254006 (rate limited).

Common situations: App lacking im:resource scope, uploading a non-image or corrupted payload, exceeding Feishu image size limits (e.g. >10MB), or bot being rate-limited.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/28c0fbcf460b606f. Report an issue: GitHub.