chenhg5/cc-connect · error

%s: upload video: no file_key returned

Error message

%s: upload video: no file_key returned

What it means

The upload call reported success, but the response body contains no Data.FileKey, which is mandatory to construct the media message. This is treated as a malformed/unexpected API response and fails fast instead of sending a message with an empty file key.

Source

Thrown at platform/feishu/feishu.go:5578

					FileName(fileName).
					File(bytes.NewReader(video)).
					Build()).
				Build()
			var err error
			uploadResp, err = client.Im.File.Create(ctx, req, options...)
			if err != nil {
				return fmt.Errorf("%s: upload video: %w", p.tag(), err)
			}
			if !uploadResp.Success() {
				return fmt.Errorf("%s: upload video 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 video: no file_key returned", p.tag())
	}
	fileKey := *uploadResp.Data.FileKey

	slog.Debug(p.tag()+": video uploaded", "file_key", fileKey, "format", format, "size", len(video))

	mediaMsg := larkim.MessageMedia{FileKey: fileKey}
	mediaContent, err := mediaMsg.String()
	if err != nil {
		return fmt.Errorf("%s: build video message: %w", p.tag(), err)
	}

	return p.sendMediaMessage(ctx, rc, larkim.MsgTypeMedia, mediaContent)
}

type postElement struct {
	Tag      string `json:"tag"`
	Text     string `json:"text,omitempty"`
	Language string `json:"language,omitempty"`

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Check the SDK version (github.com/larksuite/oapi-sdk-go) and upgrade to latest — field deserialization bugs are fixed in newer versions
  2. Log the raw response body to confirm whether Feishu actually omitted file_key
  3. Retry the upload; a transient gateway issue can produce truncated responses
  4. Verify no response-modifying proxy/middleware is stripping the JSON body
  5. If persistent, file an issue with Feishu support including request ID

Example fix

// before
if uploadResp.Data == nil || uploadResp.Data.FileKey == nil {
    return fmt.Errorf("%s: upload video: no file_key returned", p.tag())
}
// after: retry once on missing key before giving up
if uploadResp.Data == nil || uploadResp.Data.FileKey == nil {
    // retry upload once, then fall back to the error
    return fmt.Errorf("%s: upload video: no file_key returned", p.tag())
}
Defensive patterns

Strategy: retry

Type guard

if uploadResp.Data == nil || uploadResp.Data.FileKey == nil { /* retry or fail */ }

Prevention

When it happens

Trigger: Im.File.Create returns Success()==true but uploadResp.Data is nil or Data.FileKey is nil — an unexpected response shape from Feishu (API behavior change, partial response, SDK version mismatch).

Common situations: Upgrading/using a mismatched larksuite/oapi-sdk version where response fields aren't deserialized; Feishu returns a success envelope without a file_key; proxy mangling the response body.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


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