siyuan-note/siyuan · error
image exceeds size limit
Error message
image exceeds size limit: %d bytes
What it means
PrepareModelImage enforces an optional maxBytes cap and returns this error when the raw image is larger than allowed. The limit exists because multimodal providers reject or degrade oversized uploads; scaling happens later only for pixel/edge limits, so byte-size must pass this gate first. The error names the configured limit in bytes.
Solutions
- Compress or downscale the image before attaching (export as JPEG/WebP at lower quality or dimensions)
- Raise the configured maxBytes limit if your provider accepts larger uploads
- Convert PNG screenshots to JPEG — photographs in PNG are often 5-10x larger than needed
- Crop unused regions of screenshots before inserting into the document
Example fix
// before prepared, err := PrepareModelImage(hugePNG, 5*1024*1024, maxPixels, maxEdge) // 12MB PNG // after jpegData := encodeJPEG(downscale(hugePNG, 1600, 0.8)) // ~400KB prepared, err := PrepareModelImage(jpegData, 5*1024*1024, maxPixels, maxEdge)
Defensive patterns
Strategy: validation
Validate before calling
if maxBytes > 0 && len(data) > maxBytes {
data = compressImage(data, maxBytes) // downscale/re-encode before calling
} Try / catch
prepared, err := PrepareModelImage(data, maxBytes, maxPixels, maxEdge)
if err != nil && strings.Contains(err.Error(), "size limit") {
prepared, err = PrepareModelImage(recompress(data, maxBytes/2), maxBytes, maxPixels, maxEdge)
} Prevention
- Convert screenshots to JPEG/WebP instead of storing large PNGs
- Know your provider's upload cap and set maxBytes just under it
- Downscale high-DPI captures to ~1600px on the long edge before inserting
When it happens
Trigger: Calling PrepareModelImage with data longer than maxBytes — e.g. attaching a multi-megabyte photo/scan to an AI chat when the configured size limit is smaller.
Common situations: Pasting screenshots from high-DPI displays; inserting camera photos; assets created before a stricter size limit was configured; provider-specific upload caps (commonly ~5-20MB).
Understand the failure class
Background: "File too large" / "file size exceeds limit" errors: why libraries cap file sizes and how to fix them — this error's family across 46 libraries.
Related errors
- BASE64_IMAGE_SIZE_LIMIT
- decode image failed:
- encode image failed:
- generated image exceeds size limit
- image data is empty
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/7f09eb89e1fa98c9.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/util/openai.go:766
seen := make(map[int]bool, len(indices))
for _, index := range indices {
if seen[index] {
err = fmt.Errorf("rerank returned duplicate index %d", index)
return
}
seen[index] = true
}
matched = true
return
}
// PrepareModelImage 校验并按需缩放图片,尽量保留多模态模型支持的原始格式和图片质量。
func PrepareModelImage(data []byte, maxBytes, maxPixels, maxEdge int) (PreparedImage, error) {
if len(data) == 0 {
return PreparedImage{}, errors.New("image data is empty")
}
if maxBytes > 0 && len(data) > maxBytes {
return PreparedImage{}, fmt.Errorf("image exceeds size limit: %d bytes", maxBytes)
}
mimeType := mimetype.Detect(data).String()
if strings.Contains(mimeType, "svg") || bytes.Contains(bytes.ToLower(data[:min(len(data), 512)]), []byte("<svg")) {
return PreparedImage{}, errors.New("SVG images are not accepted by multimodal models")
}
switch mimeType {
case "image/gif", "image/jpeg", "image/png", "image/webp":
default:
return PreparedImage{}, fmt.Errorf("unsupported image type: %s", mimeType)
}
config, _, err := image.DecodeConfig(bytes.NewReader(data))
if err != nil {
return PreparedImage{}, errors.New("unsupported or invalid image: " + err.Error())
}
if config.Width < 1 || config.Height < 1 || maxPixels > 0 && int64(config.Width)*int64(config.Height) > int64(maxPixels) {
return PreparedImage{}, fmt.Errorf("image exceeds pixel limit: %d", maxPixels)
}
View on GitHub (pinned to 9f775e8a12)