Tencent/WeKnora · error
invalid image content type: %s
Error message
invalid image content type: %s
What it means
For image attachments small enough for direct vision input, the service sniffs the content with http.DetectContentType; if the detected media type does not start with "image/", the bytes are not a valid image and this error is returned instead of building a data URL.
Source
Thrown at internal/im/service.go:666
result, err = nil, nil
}
}
if result == nil && docparser.IsSimpleFormat(attachment.FileType) {
result, err = (&docparser.SimpleFormatReader{}).Read(attachmentCtx, request)
} else if result == nil && !isImage && s.documentReader != nil {
result, err = s.documentReader.Read(attachmentCtx, request)
}
if err != nil {
logger.Warnf(ctx, "[IM] attachment parsing failed, continuing with attachment metadata: %v", err)
}
if result != nil {
applyIMAttachmentTruncation(result.MarkdownContent, &attachment)
}
var imageURLs []string
if isImage && len(content) <= maxIMVisionAttachmentBytes {
mediaType := http.DetectContentType(content)
if !strings.HasPrefix(mediaType, "image/") {
return nil, nil, nil, fmt.Errorf("invalid image content type: %s", mediaType)
}
imageURLs = []string{"data:" + mediaType + ";base64," + base64.StdEncoding.EncodeToString(content)}
} else if isImage {
logger.Warnf(ctx, "[IM] image is too large for direct vision input: size=%d limit=%d", len(content), maxIMVisionAttachmentBytes)
}
return types.MessageAttachments{attachment}, imageURLs, &imDownloadedAttachment{fileName: fileName, content: content}, nil
}
func applyIMAttachmentTruncation(content string, attachment *types.MessageAttachment) {
attachment.LineCount = strings.Count(content, "\n") + 1
limited := truncateUTF8ByBytes(content, maxIMAttachmentContentBytes)
lines := strings.SplitN(limited, "\n", maxIMAttachmentLines+1)
if len(lines) > maxIMAttachmentLines {
limited = strings.Join(lines[:maxIMAttachmentLines], "\n")
}
attachment.Content = limitedView on GitHub (pinned to 988cbb0330)
Solutions
- Verify the file is a real image and resend it
- Re-download the source — the original fetch may have returned an error page
- Convert the file to png/jpg before sending, or send it as a document rather than an image
Defensive patterns
Strategy: validation
Validate before calling
head := content[:min(512, len(content))]
if !strings.HasPrefix(http.DetectContentType(head), "image/") {
return errors.New("not a valid image")
} Type guard
func isImageBytes(b []byte) bool {
return strings.HasPrefix(http.DetectContentType(b), "image/")
} Prevention
- Download images over HTTPS from trusted sources; handle non-200 responses that return HTML error pages
- Validate extensions vs actual MIME type before sending image-typed messages
When it happens
Trigger: A message typed as image (or an image-like extension such as png/jpg) whose downloaded bytes are not actually an image — DetectContentType returns e.g. text/plain or application/octet-stream.
Common situations: Renamed files (a .png that is actually text/HTML); an HTML error page saved as an image URL; corrupted or truncated uploads; SVG or exotic formats DetectContentType classifies as text.
Related errors
- non-image content type: %s
- cannot run workspace script %q for skill %q: no installed sk
- invite code has expired
- join request not found
- failed to retrieve: %s
AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02).
Data as JSON: /api/errors/3fe1e100bfb0b249.
Report an issue: GitHub.