{"record":{"id":"302823f009d79189","repo":"alibaba/spring-ai-alibaba","slug":"file-not-found","errorCode":"FILE_NOT_FOUND","errorMessage":"File not found: + filePath","messagePattern":"File not found: \\+ filePath","errorType":"error_code","errorClass":"BizException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/manager/FileManager.java","lineNumber":137,"sourceCode":"\t\t\t\treturn new UrlResource(url);\n\t\t\t}\n\t\t\tcatch (MalformedURLException e) {\n\t\t\t\tthrow new RuntimeException(e);\n\t\t\t}\n\t\t}\n\n\t\tString storagePath = studioProperties.getStoragePath();\n\t\tPath basePath = Paths.get(storagePath).toAbsolutePath().normalize();\n\t\tPath targetPath = basePath.resolve(filePath).toAbsolutePath().normalize();\n\n\t\tif (!targetPath.startsWith(basePath)) {\n\t\t\tlog.warn(\"Path traversal attempt detected: {}\", filePath);\n\t\t\tthrow new BizException(ErrorCode.INVALID_PARAMS.toError(\"path\", \"Invalid file path\"));\n\t\t}\n\n\t\tFile file = targetPath.toFile();\n\t\tif (!file.exists()) {\n\t\t\tthrow new BizException(ErrorCode.FILE_NOT_FOUND.toError(\"File not found: \" + filePath));\n\t\t}\n\n\t\treturn new FileSystemResource(file);\n\t}\n\n\t/**\n\t * Determines the media type of a file from its URL by analyzing the file header.\n\t * Supports common formats including JPEG, PNG, GIF, PDF, XML, and JSON.\n\t * @param url The URL of the file\n\t * @return The detected MediaType\n\t * @throws BizException if the media type cannot be determined or is invalid\n\t */\n\tpublic MediaType getMediaTypeFromUrl(String url) {\n\t\ttry {\n\t\t\tURL imageUrl = new URL(url);\n\t\t\t// noinspection StartSSRFNetHookCheckingInspection\n\t\t\tjava.io.InputStream is = imageUrl.openStream();\n\t\t\tbyte[] bytes = new byte[Math.min(is.available(), 1024)]; // 读取前1KB用于识别","sourceCodeStart":119,"sourceCodeEnd":155,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/manager/FileManager.java#L119-L155","documentation":"Thrown by FileManager.loadFile when the resolved file does not exist on local storage. Fires after path-traversal validation passes but targetPath.toFile().exists() returns false — typically stale references, deleted files, or a mismatched storagePath configuration.","triggerScenarios":"Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/manager/FileManager.java:137 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the filePath/id refers to a file that was successfully uploaded","Check studioProperties.storagePath matches the environment the file was uploaded to","Handle BizException in the caller and return a 404-style response to the client","Re-upload the file if it was removed from disk"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}