wavetermdev/waveterm · error

no data available for base64 extraction

Error message

no data available for base64 extraction

What it means

extractBase64Data in pkg/aiusechat/anthropic/anthropic-convertmessage.go builds base64-encoded media data for Anthropic message content blocks. It handles 'data:' URLs (base64 or raw payloads) and raw data, but if the input string yields no extractable data it falls through to this error. It signals that the file AI message part contained no usable data payload to encode.

Source

Thrown at pkg/aiusechat/anthropic/anthropic-convertmessage.go:533

		parts := strings.SplitN(part.URL, ",", 2)
		if len(parts) != 2 {
			return "", errors.New("invalid data URL format")
		}

		header := parts[0]
		data := parts[1]

		// Check if it's already base64 encoded: data:mediatype;base64,<data>
		if strings.Contains(header, ";base64") {
			// Already base64 encoded
			return data, nil
		} else {
			// Raw data that needs base64 encoding: data:mediatype,<raw_data>
			return base64.StdEncoding.EncodeToString([]byte(data)), nil
		}
	}

	return "", errors.New("no data available for base64 extraction")
}

// convertFileAIMessagePart converts a file AIMessagePart to anthropicMessageContentBlock
func convertFileAIMessagePart(part uctypes.AIMessagePart) (*anthropicMessageContentBlock, error) {
	if part.Type != uctypes.AIMessagePartTypeFile {
		return nil, fmt.Errorf("convertFileAIMessagePart expects 'file' type, got '%s'", part.Type)
	}

	if err := part.Validate(); err != nil {
		return nil, err
	}

	// Validate URL protocol if URL is provided - only allow data:, http:, https:
	if part.URL != "" {
		if !strings.HasPrefix(part.URL, "data:") &&
			!strings.HasPrefix(part.URL, "http://") &&
			!strings.HasPrefix(part.URL, "https://") {
			return nil, fmt.Errorf("unsupported URL protocol in file part: %s", part.URL)

View on GitHub (pinned to a4447c1563)

Solutions

  1. Check that the file AIMessagePart's data field is non-empty before adding the part to the AI message
  2. Verify data: URLs are well formed: 'data:<mediatype>;base64,<payload>' with an actual base64 payload after the comma
  3. Re-generate or re-capture the file content on the client side and resend the message
  4. If the file is only available as a path or URL (not inline data), convert it to base64 first instead of passing it to convertFileAIMessagePart

Example fix

// before
part := uctypes.AIMessagePart{Type: uctypes.AIMessagePartTypeFile, Data: dataUrl}
// after
if dataUrl == "" || !strings.Contains(dataUrl, ",") {
    return fmt.Errorf("file part %q has no data payload", partName)
}
part := uctypes.AIMessagePart{Type: uctypes.AIMessagePartTypeFile, Data: dataUrl}
Defensive patterns

Strategy: validation

Validate before calling

func filePartHasData(part uctypes.AIMessagePart) bool {
    if part.Type != uctypes.AIMessagePartTypeFile || part.Data == "" {
        return false
    }
    if strings.HasPrefix(part.Data, "data:") {
        return strings.Contains(part.Data, ",") && len(strings.SplitN(part.Data, ",", 2)[1]) > 0
    }
    return true
}

Prevention

When it happens

Trigger: convertFileAIMessagePart receives an AIMessagePart of type 'file' whose Data (or equivalent data string) is empty, is a malformed data: URL with an empty payload (e.g. 'data:image/png,' with nothing after the comma and no raw fallback), or otherwise does not match any of the extraction branches, so the function reaches the trailing 'return "", errors.New(...)' at line 533.

Common situations: Frontend uploads a file attachment with metadata but the binary content was never populated; a data URL was truncated or hand-constructed incorrectly; a paste/screenshot capture produced an empty payload; middleware stripped the data field during message serialization.

Related errors


AI-assisted analysis of wavetermdev/waveterm@a4447c1563 (2026-09-01). Data as JSON: /api/errors/bb574925904e61aa. Report an issue: GitHub.