chenhg5/cc-connect · error

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

Error message

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

What it means

The Feishu file upload API responded but with a business error: uploadResp.Success() is false. The library surfaces the API's numeric code and message so the developer can identify the Feishu-side failure (permissions, file constraints, rate limits).

Source

Thrown at platform/feishu/feishu.go:3338

	}
	fileType := detectFeishuFileType(file.MimeType, fileName)
	var uploadResp *larkim.CreateFileResp
	if err := p.withTransientRetry(ctx, "upload file", func() error {
		return p.withFreshTenantAccessTokenRetry(ctx, "upload file", func(client *lark.Client, options ...larkcore.RequestOptionFunc) error {
			req := larkim.NewCreateFileReqBuilder().
				Body(larkim.NewCreateFileReqBodyBuilder().
					FileType(fileType).
					FileName(fileName).
					File(bytes.NewReader(file.Data)).
					Build()).
				Build()
			var err error
			uploadResp, err = client.Im.File.Create(ctx, req, options...)
			if err != nil {
				return fmt.Errorf("%s: upload file: %w", p.tag(), err)
			}
			if !uploadResp.Success() {
				return fmt.Errorf("%s: upload file code=%d msg=%s", p.tag(), uploadResp.Code, uploadResp.Msg)
			}
			return nil
		})
	}); err != nil {
		return err
	}
	if uploadResp.Data == nil || uploadResp.Data.FileKey == nil {
		return fmt.Errorf("%s: upload file: no file_key returned", p.tag())
	}

	msgType := detectFeishuFileMessageType(fileType)
	fileContent, err := buildFeishuFileMessageContent(msgType, *uploadResp.Data.FileKey)
	if err != nil {
		return fmt.Errorf("%s: build file message: %w", p.tag(), err)
	}

	return p.sendMediaMessage(ctx, rc, msgType, fileContent)
}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Look up the printed code in Feishu's open-platform error code list.
  2. Check/raise against the 30MB file size limit; compress or split large files before upload.
  3. Grant im:resource permission to the app and republish the app version.
  4. Back off and retry if the code indicates rate limiting.
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check: file type must be one of Feishu-supported Im.File.Create types
// (opus, mp4, pdf, doc, xls, ppt, stream) and size <= 30MB.

Try / catch

err := p.SendFile(ctx, rc, file)
if err != nil && strings.Contains(err.Error(), "upload file code=") {
    // parse code=N from message and branch on known Feishu error codes
}

Prevention

When it happens

Trigger: client.Im.File.Create returns a success-flag-false response at platform/feishu/feishu.go:3338 — e.g. code 230002 (file too large, Feishu limit ~30MB), 99991672 (no permission), or 1254045 rate limit.

Common situations: Uploading files larger than Feishu's 30MB limit, unsupported file_type for the Im.File.Create request, app missing im:resource permission, bot throttled by Feishu.

Related errors


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