{"record":{"id":"86e1abb08747cae2","repo":"chenhg5/cc-connect","slug":"s-is-not-s-media-detected-mime-s","errorCode":null,"errorMessage":"%s is not %s media (detected mime: %s)","messagePattern":"(.+?) is not (.+?) media \\(detected mime: (.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/send.go","lineNumber":253,"sourceCode":"\tfor _, path := range paths {\n\t\tdata, fileName, mimeType, err := readAttachment(path, maxSize)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tfiles = append(files, core.FileAttachment{MimeType: mimeType, Data: data, FileName: fileName})\n\t}\n\treturn files, nil\n}\n\nfunc loadTypedFileAttachments(paths []string, mediaType string, maxSize int64) ([]core.FileAttachment, error) {\n\tfiles := make([]core.FileAttachment, 0, len(paths))\n\tfor _, path := range paths {\n\t\tdata, fileName, mimeType, err := readAttachment(path, maxSize)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tif !attachmentMatchesMediaType(mimeType, fileName, mediaType) {\n\t\t\treturn nil, fmt.Errorf(\"%s is not %s media (detected mime: %s)\", path, mediaType, mimeType)\n\t\t}\n\t\tfiles = append(files, core.FileAttachment{MimeType: mimeType, Data: data, FileName: fileName})\n\t}\n\treturn files, nil\n}\n\nfunc attachmentMatchesMediaType(mimeType, fileName, mediaType string) bool {\n\text := strings.ToLower(filepath.Ext(fileName))\n\tswitch mediaType {\n\tcase \"audio\":\n\t\tif strings.HasPrefix(mimeType, \"audio/\") {\n\t\t\treturn true\n\t\t}\n\t\tswitch ext {\n\t\tcase \".aac\", \".flac\", \".m4a\", \".mp3\", \".oga\", \".ogg\", \".opus\", \".wav\":\n\t\t\treturn true\n\t\t}\n\tcase \"video\":","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/send.go#L235-L271","documentation":"loadTypedFileAttachments verifies that every attachment supplied via `cc-connect send --media-type <type>` actually matches the requested media type. It compares the mime type detected from the file content/filename (via detectAttachmentMimeType) against the requested mediaType using attachmentMatchesMediaType; on mismatch it refuses the file rather than sending a wrongly-typed attachment to the platform. This prevents e.g. an image agent API from receiving a PDF that was passed by mistake.","triggerScenarios":"Running `cc-connect send ... --media-type image` (or similar) while one of the given paths is a non-image file (e.g. a .txt, .pdf, or .mp4), so detectAttachmentMimeType returns a mime that does not satisfy attachmentMatchesMediaType for the requested type.","commonSituations":"Passing a glob that picks up non-matching files (e.g. `./assets/*` picking up a README), renaming a file with an image extension when it is actually another format, or confusing image vs file attachments on the send command.","solutions":["Check the detected mime in the error message and replace the offending path with a file that matches the requested media type","Drop --media-type so the file is loaded as a generic file attachment (loadFileAttachments) instead of typed media","Fix the file extension if the content is actually of the requested type but named wrongly, so mime detection classifies it correctly"],"exampleFix":"// before\ncc-connect send --media-type image ./assets/*\n// after\ncc-connect send --media-type image ./assets/photo.png ./assets/diagram.jpg","handlingStrategy":"validation","validationCode":"file=\"./assets/photo.png\"; file \"$file\"  # verify mime matches --media-type before running send","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use explicit file paths instead of loose globs","Check `file <path>` output when unsure of real content type","Prefer generic file attachments when type filtering is not needed"],"tags":["cli","attachments","media-type","validation"],"backgroundTag":"incompatible-source-type","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}