{"record":{"id":"8d79b460ae0d1961","repo":"siyuan-note/siyuan","slug":"image-mime-type-is-missing","errorCode":null,"errorMessage":"image MIME type is missing","messagePattern":"image MIME type is missing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/agent/attachments.go","lineNumber":146,"sourceCode":"\tif imageCount == 0 {\n\t\treturn openai.ChatCompletionMessage{}, false\n\t}\n\tif omitted {\n\t\tparts = append(parts, openai.ChatMessagePart{\n\t\t\tType: openai.ChatMessagePartTypeText,\n\t\t\tText: \"One or more image attachments were omitted because they were unavailable or exceeded the request limit.\",\n\t\t})\n\t}\n\treturn openai.ChatCompletionMessage{\n\t\tRole:         openai.ChatMessageRoleUser,\n\t\tMultiContent: parts,\n\t}, true\n}\n\nfunc resolveAgentAttachment(attachment AgentAttachment) (data []byte, mimeType string, width, height int, err error) {\n\tif len(attachment.Data) > 0 {\n\t\tif attachment.MIMEType == \"\" {\n\t\t\terr = fmt.Errorf(\"image MIME type is missing\")\n\t\t\treturn\n\t\t}\n\t\tdata = attachment.Data\n\t\tmimeType = attachment.MIMEType\n\t\twidth = attachment.Width\n\t\theight = attachment.Height\n\t\treturn\n\t}\n\tvar prepared kernelModel.PreparedDocumentImage\n\tvar prepareErr error\n\tif attachment.DocumentID == \"\" {\n\t\tprepared, prepareErr = kernelModel.PrepareAgentMessageImage(attachment.Path)\n\t} else {\n\t\tprepared, prepareErr = kernelModel.PrepareDocumentImage(attachment.DocumentID, attachment.Path)\n\t}\n\tif prepareErr != nil {\n\t\terr = prepareErr\n\t\treturn","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/agent/attachments.go#L128-L164","documentation":"resolveAgentAttachment requires a MIME type whenever raw attachment Data is present, because the data cannot be turned into a valid image content part for the model without knowing its type. A missing MIMEType with non-empty Data produces this error.","triggerScenarios":"buildAttachmentMessage calls resolveAgentAttachment with an AgentAttachment whose Data is non-empty but MIMEType is \"\" — the named-return err is set and the attachment resolution aborts.","commonSituations":"Frontend or plugin builds AgentAttachment structs manually and forgets MIMEType; attachments deserialized from older/external payloads that omit the MIME field; clipboard pastes where the MIME type was not detected.","solutions":["Set MIMEType (e.g. \"image/png\") on every attachment that carries Data","Detect the MIME type from the file signature or the source paste event before sending","Default missing MIME types to \"image/png\" at the attachment-production site if that matches the data","Validate attachments in the frontend before posting them to the agent"],"exampleFix":"// before\nattach := AgentAttachment{Data: pngBytes}\n// after\nattach := AgentAttachment{Data: pngBytes, MIMEType: \"image/png\"}","handlingStrategy":"validation","validationCode":"function isValidAttachment(a) {\n  return !(a.data && a.data.length > 0) || Boolean(a.mimeType)\n}","typeGuard":"function hasMIME(a) { return typeof a.MIMEType === \"string\" && a.MIMEType !== \"\" }","tryCatchPattern":null,"preventionTips":["Always populate MIMEType when constructing AgentAttachment values","Detect MIME from magic bytes at paste/import time","Add a constructor/helper that rejects attachments without a MIME type"],"tags":["agent","attachments","mime","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}