siyuan-note/siyuan · error

image exceeds size limit: %d bytes

Error message

image exceeds size limit: %d bytes

What it means

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).

Source

Thrown at kernel/util/openai.go:626

	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 251596fc0d)

Solutions

  1. Resize/compress the source image on the client before sending.
  2. Raise maxBytes if the provider allows a larger upload.
  3. Reject over-large assets at the UI with a clear message before upload.
Defensive patterns

Strategy: validation

Validate before calling

if maxBytes > 0 && len(data) > maxBytes {
    return fmt.Errorf("source image %d bytes exceeds %d", len(data), maxBytes)
}

Type guard

func WithinByteLimit(data []byte, max int) bool { return max <= 0 || len(data) <= max }

Prevention

When it happens

Trigger: 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).

Common situations: Full-resolution phone photos; large uncompressed PNGs; maxBytes tuned conservatively.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/7f09eb89e1fa98c9. Report an issue: GitHub.