chenhg5/cc-connect · error

%s: image download: %w

Error message

%s: image download: %w

What it means

Wraps a failure from downloadResourceChunked when fetching an image attached to a Feishu message. The library routes image downloads through a chunked helper (instead of the SDK's ~2MiB streaming ceiling) so large screenshots download whole; this error means that chunked download failed (HTTP error, auth, missing message permissions).

Source

Thrown at platform/feishu/feishu.go:3423

	switch msgType {
	case larkim.MsgTypeAudio:
		return (&larkim.MessageAudio{FileKey: fileKey}).String()
	case larkim.MsgTypeMedia:
		return (&larkim.MessageMedia{FileKey: fileKey}).String()
	default:
		return (&larkim.MessageFile{FileKey: fileKey}).String()
	}
}

func (p *Platform) downloadImage(messageID, imageKey string) ([]byte, string, error) {
	// Issue #1741: large image bodies suffer the same code=234037 truncation
	// as files when fetched through the larkim SDK (which cannot set Range
	// headers). Route image downloads through the same chunked helper used
	// for files so a 20-MiB screenshot lands whole instead of being capped
	// at the SDK's ~2 MiB streaming ceiling.
	data, err := p.downloadResourceChunked(context.Background(), messageID, imageKey, "image")
	if err != nil {
		return nil, "", fmt.Errorf("%s: image download: %w", p.tag(), err)
	}

	mimeType := detectMimeType(data)
	slog.Debug(p.tag()+": downloaded image", "key", imageKey, "size", len(data), "mime", mimeType)
	return data, mimeType, nil
}

func (p *Platform) downloadResource(messageID, fileKey, resType string) ([]byte, error) {
	// Issue #1741: the larkim SDK issues a plain GET that Feishu truncates
	// with code=234037 for resources above ~2 MiB. downloadResourceChunked
	// bypasses the SDK, sends Range headers, and reassembles the bytes
	// client-side. All four existing call sites (audio body, file body,
	// merge_forward file, #1588 quoted file) flow through here unchanged.
	data, err := p.downloadResourceChunked(context.Background(), messageID, fileKey, resType)
	if err != nil {
		return nil, err
	}
	slog.Debug(p.tag()+": downloaded resource", "key", fileKey, "type", resType, "size", len(data))

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Inspect the wrapped error: 230013 / permission errors require im:message resources scope.
  2. Verify messageID and imageKey come from the same, still-existing message.
  3. Retry on transient network/chunk errors; the chunked helper should be resumable.
  4. Confirm tenant token validity and that the host can reach the Feishu resource endpoints.
Defensive patterns

Strategy: retry

Validate before calling

if messageID == "" || imageKey == "" {
    return errors.New("message_id and image_key are required for image download")
}

Try / catch

data, mime, err := p.DownloadImage(ctx, messageID, imageKey)
if err != nil {
    if strings.Contains(err.Error(), "image download") && isRetryable(err) {
        // retry chunked download with backoff
    }
    return fmt.Errorf("cannot fetch image: %w", err)
}

Prevention

When it happens

Trigger: p.downloadResourceChunked(ctx, messageID, imageKey, "image") returns an error at platform/feishu/feishu.go:3423 — e.g. 404 for an expired/deleted message, 403 without im:message permission, network interruption mid-chunk.

Common situations: Trying to download an image from a message older than Feishu's retention or already revoked; bot lacking im:message:readonly scope; token expired mid-download; large image exceeding per-request limits in a chunk.

Understand the failure class

Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.

Related errors


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