{"record":{"id":"58bd30911a538665","repo":"siyuan-note/siyuan","slug":"prepared-image-exceeds-size-limit-d-bytes","errorCode":null,"errorMessage":"prepared image exceeds size limit: %d bytes","messagePattern":"prepared image exceeds size limit: (.+?) bytes","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":684,"sourceCode":"\t\tif err = png.Encode(&output, decoded); err != nil {\n\t\t\treturn PreparedImage{}, errors.New(\"encode image failed: \" + err.Error())\n\t\t}\n\t\tif maxBytes <= 0 || output.Len() <= maxBytes {\n\t\t\treturn PreparedImage{\n\t\t\t\tData:       output.Bytes(),\n\t\t\t\tMIMEType:   \"image/png\",\n\t\t\t\tWidth:      bounds.Dx(),\n\t\t\t\tHeight:     bounds.Dy(),\n\t\t\t\tSourceSize: len(data),\n\t\t\t}, nil\n\t\t}\n\t}\n\tvar output bytes.Buffer\n\tif err = jpeg.Encode(&output, decoded, &jpeg.Options{Quality: 92}); err != nil {\n\t\treturn PreparedImage{}, errors.New(\"encode image failed: \" + err.Error())\n\t}\n\tif maxBytes > 0 && output.Len() > maxBytes {\n\t\treturn PreparedImage{}, fmt.Errorf(\"prepared image exceeds size limit: %d bytes\", maxBytes)\n\t}\n\treturn PreparedImage{\n\t\tData:       output.Bytes(),\n\t\tMIMEType:   \"image/jpeg\",\n\t\tWidth:      bounds.Dx(),\n\t\tHeight:     bounds.Dy(),\n\t\tSourceSize: len(data),\n\t}, nil\n}\n\n// ValidateGeneratedImage 校验生成图片的格式、尺寸和体积。\nfunc ValidateGeneratedImage(data []byte) (mimeType, extension string, err error) {\n\tif len(data) == 0 {\n\t\treturn \"\", \"\", errors.New(\"generated image is empty\")\n\t}\n\tif len(data) > maxGeneratedImageBytes {\n\t\treturn \"\", \"\", errors.New(\"generated image exceeds size limit\")\n\t}","sourceCodeStart":666,"sourceCodeEnd":702,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/251596fc0de2f9528c00c224252fd073a99973f4/kernel/util/openai.go#L666-L702","documentation":"After all processing (resize, PNG encode, final JPEG quality-92 encode) the output STILL exceeds maxBytes. The image cannot be compressed under the cap at quality 92, so it is rejected.","triggerScenarios":"Very large or complex image whose JPEG q92 output is still over maxBytes (e.g. 20MP photo with maxBytes=1MB).","commonSituations":"Aggressive maxBytes combined with high-resolution input; provider with a tight upload cap.","solutions":["Downscale the source resolution before sending.","Pre-compress to a lower JPEG quality externally.","Raise maxBytes if the provider allows a larger upload."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"img, err := util.PrepareModelImage(data, maxBytes, maxPixels, maxEdge)\nif err != nil {\n    log.Warnf(\"image too large for vision budget after encode: %s\", err)\n    return skipImage()\n}","preventionTips":["Downscale before attaching to fit the byte budget","Tune maxBytes to the provider's actual cap"],"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"}