{"record":{"id":"3fe1e100bfb0b249","repo":"Tencent/WeKnora","slug":"invalid-image-content-type-s","errorCode":null,"errorMessage":"invalid image content type: %s","messagePattern":"invalid image content type: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/im/service.go","lineNumber":666,"sourceCode":"\t\t\tresult, err = nil, nil\n\t\t}\n\t}\n\tif result == nil && docparser.IsSimpleFormat(attachment.FileType) {\n\t\tresult, err = (&docparser.SimpleFormatReader{}).Read(attachmentCtx, request)\n\t} else if result == nil && !isImage && s.documentReader != nil {\n\t\tresult, err = s.documentReader.Read(attachmentCtx, request)\n\t}\n\tif err != nil {\n\t\tlogger.Warnf(ctx, \"[IM] attachment parsing failed, continuing with attachment metadata: %v\", err)\n\t}\n\tif result != nil {\n\t\tapplyIMAttachmentTruncation(result.MarkdownContent, &attachment)\n\t}\n\tvar imageURLs []string\n\tif isImage && len(content) <= maxIMVisionAttachmentBytes {\n\t\tmediaType := http.DetectContentType(content)\n\t\tif !strings.HasPrefix(mediaType, \"image/\") {\n\t\t\treturn nil, nil, nil, fmt.Errorf(\"invalid image content type: %s\", mediaType)\n\t\t}\n\t\timageURLs = []string{\"data:\" + mediaType + \";base64,\" + base64.StdEncoding.EncodeToString(content)}\n\t} else if isImage {\n\t\tlogger.Warnf(ctx, \"[IM] image is too large for direct vision input: size=%d limit=%d\", len(content), maxIMVisionAttachmentBytes)\n\t}\n\treturn types.MessageAttachments{attachment}, imageURLs, &imDownloadedAttachment{fileName: fileName, content: content}, nil\n}\n\nfunc applyIMAttachmentTruncation(content string, attachment *types.MessageAttachment) {\n\tattachment.LineCount = strings.Count(content, \"\\n\") + 1\n\n\tlimited := truncateUTF8ByBytes(content, maxIMAttachmentContentBytes)\n\tlines := strings.SplitN(limited, \"\\n\", maxIMAttachmentLines+1)\n\tif len(lines) > maxIMAttachmentLines {\n\t\tlimited = strings.Join(lines[:maxIMAttachmentLines], \"\\n\")\n\t}\n\n\tattachment.Content = limited","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/im/service.go#L648-L684","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"head := content[:min(512, len(content))]\nif !strings.HasPrefix(http.DetectContentType(head), \"image/\") {\n    return errors.New(\"not a valid image\")\n}","typeGuard":"func isImageBytes(b []byte) bool {\n    return strings.HasPrefix(http.DetectContentType(b), \"image/\")\n}","tryCatchPattern":null,"preventionTips":["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"],"tags":["image","content-type","validation"],"backgroundTag":"invalid-content-type","analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}