{"record":{"id":"37624d1b4d412a39","repo":"siyuan-note/siyuan","slug":"assetpath-is-not-an-image-referenced-by-the-docume","errorCode":null,"errorMessage":"assetPath is not an image referenced by the document","messagePattern":"assetPath is not an image referenced by the document","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/assets.go","lineNumber":465,"sourceCode":"\t}\n\treturn DocumentImageList{DocumentID: bt.RootID, Images: refs}, nil\n}\n\n// PrepareDocumentImage 校验并读取文档实际引用的本地资源图片，供当前模型直接接收图片输入。\nfunc PrepareDocumentImage(documentID, assetPath string) (PreparedDocumentImage, error) {\n\tassetPath = strings.TrimSpace(assetPath)\n\tif assetPath == \"\" {\n\t\treturn PreparedDocumentImage{}, errors.New(\"assetPath is required for analyze\")\n\t}\n\tif !strings.HasPrefix(AssetPathWithoutQuery(assetPath), \"assets/\") {\n\t\treturn PreparedDocumentImage{}, errors.New(\"only local assets/... images are supported\")\n\t}\n\tbt, err := resolveMultimodalDocument(documentID)\n\tif err != nil {\n\t\treturn PreparedDocumentImage{}, err\n\t}\n\tif !documentReferencesImage(bt.RootID, assetPath) {\n\t\treturn PreparedDocumentImage{}, errors.New(\"assetPath is not an image referenced by the document\")\n\t}\n\tdata, err := ReadAssetBytesInBox(bt.BoxID, assetPath)\n\tif err != nil {\n\t\treturn PreparedDocumentImage{}, fmt.Errorf(\"read image failed: %w\", err)\n\t}\n\tprepared, err := util.PrepareModelImage(\n\t\tdata, documentImageMaxBytes, documentImageMaxPixels, documentImageMaxEdge,\n\t)\n\tif err != nil {\n\t\treturn PreparedDocumentImage{}, err\n\t}\n\treturn PreparedDocumentImage{\n\t\tArtifact: ImageArtifactRef{Kind: \"image\", Path: assetPath, DocumentID: bt.RootID},\n\t\tData:     prepared.Data,\n\t\tMIMEType: prepared.MIMEType,\n\t\tPrepared: prepared,\n\t}, nil\n}","sourceCodeStart":447,"sourceCodeEnd":483,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/assets.go#L447-L483","documentation":"Even a valid assets/ path is rejected unless the resolved document's tree actually references that asset as an image (documentReferencesImage check). This prevents analyzing images that belong to other documents or unreferenced files.","triggerScenarios":"Calling PrepareDocumentImage with an assets path that exists but is not referenced by documentID, or referencing it only via a non-image embed (e.g. link text rather than an img node).","commonSituations":"Reusing an image from another document; the reference was deleted from the document after the path was captured; typo in the asset filename so it no longer matches the reference.","solutions":["Open the document and confirm the image embed exists, then pass exactly the path it references","Re-copy/paste the image into the document so a fresh reference is created","Fetch the correct path via ListDocumentImages instead of hardcoding it"],"exampleFix":"// before\nPrepareDocumentImage(docID, \"assets/other-doc.png\")\n// after\nlist, _ := ListDocumentImages(docID)\nPrepareDocumentImage(docID, list.Images[0].Path)","handlingStrategy":"validation","validationCode":"list, err := ListDocumentImages(documentID)\nif err != nil || !containsPath(list, assetPath) { /* not referenced by this document */ }","typeGuard":null,"tryCatchPattern":"prepared, err := PrepareDocumentImage(docID, assetPath)\nif err != nil && strings.Contains(err.Error(), \"not an image referenced\") { return userFacingError(\"pick an image from this document\") }","preventionTips":["Derive assetPath from the target document's image list each time","Refresh captured paths after document edits (references may be deleted)","Match asset filenames exactly, including timestamp/id suffixes"],"tags":["go","validation","assets","documents"],"backgroundTag":"resource-not-found","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}