{"record":{"id":"7f09eb89e1fa98c9","repo":"siyuan-note/siyuan","slug":"image-exceeds-size-limit-d-bytes","errorCode":null,"errorMessage":"image exceeds size limit: %d bytes","messagePattern":"image exceeds size limit: (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":626,"sourceCode":"\tseen := make(map[int]bool, len(indices))\n\tfor _, index := range indices {\n\t\tif seen[index] {\n\t\t\terr = fmt.Errorf(\"rerank returned duplicate index %d\", index)\n\t\t\treturn\n\t\t}\n\t\tseen[index] = true\n\t}\n\tmatched = true\n\treturn\n}\n\n// PrepareModelImage 校验并按需缩放图片，尽量保留多模态模型支持的原始格式和图片质量。\nfunc PrepareModelImage(data []byte, maxBytes, maxPixels, maxEdge int) (PreparedImage, error) {\n\tif len(data) == 0 {\n\t\treturn PreparedImage{}, errors.New(\"image data is empty\")\n\t}\n\tif maxBytes > 0 && len(data) > maxBytes {\n\t\treturn PreparedImage{}, fmt.Errorf(\"image exceeds size limit: %d bytes\", maxBytes)\n\t}\n\tmimeType := mimetype.Detect(data).String()\n\tif strings.Contains(mimeType, \"svg\") || bytes.Contains(bytes.ToLower(data[:min(len(data), 512)]), []byte(\"<svg\")) {\n\t\treturn PreparedImage{}, errors.New(\"SVG images are not accepted by multimodal models\")\n\t}\n\tswitch mimeType {\n\tcase \"image/gif\", \"image/jpeg\", \"image/png\", \"image/webp\":\n\tdefault:\n\t\treturn PreparedImage{}, fmt.Errorf(\"unsupported image type: %s\", mimeType)\n\t}\n\tconfig, _, err := image.DecodeConfig(bytes.NewReader(data))\n\tif err != nil {\n\t\treturn PreparedImage{}, errors.New(\"unsupported or invalid image: \" + err.Error())\n\t}\n\tif config.Width < 1 || config.Height < 1 || maxPixels > 0 && int64(config.Width)*int64(config.Height) > int64(maxPixels) {\n\t\treturn PreparedImage{}, fmt.Errorf(\"image exceeds pixel limit: %d\", maxPixels)\n\t}\n","sourceCodeStart":608,"sourceCodeEnd":644,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/openai.go#L608-L644","documentation":"If maxBytes > 0 and the SOURCE image already exceeds it, PrepareModelImage rejects before any processing. This limit is on the raw bytes of the uploaded asset and is distinct from the post-encode limit (error 1139).","triggerScenarios":"User attaches a multi-MB photo to a vision query while the configured byte limit is low (e.g. a provider's 4MB upload cap).","commonSituations":"Full-resolution phone photos; large uncompressed PNGs; maxBytes tuned conservatively.","solutions":["Resize/compress the source image on the client before sending.","Raise maxBytes if the provider allows a larger upload.","Reject over-large assets at the UI with a clear message before upload."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if maxBytes > 0 && len(data) > maxBytes {\n    return fmt.Errorf(\"source image %d bytes exceeds %d\", len(data), maxBytes)\n}","typeGuard":"func WithinByteLimit(data []byte, max int) bool { return max <= 0 || len(data) <= max }","tryCatchPattern":null,"preventionTips":["Resize/compress images before attaching to vision prompts","Enforce the byte limit in the UI before upload"],"tags":["ai","multimodal","image","go","size-limit"],"backgroundTag":null,"analyzedSha":"251596fc0de2f9528c00c224252fd073a99973f4","analyzedAt":"2026-08-12T21:18:37.123Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}