alibaba/spring-ai-alibaba · error · BizException

FILE_NOT_FOUND

FILE_NOT_FOUND

Error message

File not found: + filePath

What it means

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.

Solutions

  1. Verify the filePath/id refers to a file that was successfully uploaded
  2. Check studioProperties.storagePath matches the environment the file was uploaded to
  3. Handle BizException in the caller and return a 404-style response to the client
  4. Re-upload the file if it was removed from disk
Defensive patterns

Strategy: validation

When it happens

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

Common situations: See trigger scenarios.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/302823f009d79189. Report an issue: GitHub.

Appendix: source

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

				return new UrlResource(url);
			}
			catch (MalformedURLException e) {
				throw new RuntimeException(e);
			}
		}

		String storagePath = studioProperties.getStoragePath();
		Path basePath = Paths.get(storagePath).toAbsolutePath().normalize();
		Path targetPath = basePath.resolve(filePath).toAbsolutePath().normalize();

		if (!targetPath.startsWith(basePath)) {
			log.warn("Path traversal attempt detected: {}", filePath);
			throw new BizException(ErrorCode.INVALID_PARAMS.toError("path", "Invalid file path"));
		}

		File file = targetPath.toFile();
		if (!file.exists()) {
			throw new BizException(ErrorCode.FILE_NOT_FOUND.toError("File not found: " + filePath));
		}

		return new FileSystemResource(file);
	}

	/**
	 * Determines the media type of a file from its URL by analyzing the file header.
	 * Supports common formats including JPEG, PNG, GIF, PDF, XML, and JSON.
	 * @param url The URL of the file
	 * @return The detected MediaType
	 * @throws BizException if the media type cannot be determined or is invalid
	 */
	public MediaType getMediaTypeFromUrl(String url) {
		try {
			URL imageUrl = new URL(url);
			// noinspection StartSSRFNetHookCheckingInspection
			java.io.InputStream is = imageUrl.openStream();
			byte[] bytes = new byte[Math.min(is.available(), 1024)]; // 读取前1KB用于识别

View on GitHub (pinned to f82da0b50f)