PaddlePaddle/PaddleOCR · error · FileNotFoundError
File not found: ${path}
Error message
File not found: ${path} What it means
FileNotFoundError is thrown by submitFile() in the HTTP client when the local file path you passed does not exist on disk (checked with fs.existsSync before any network call). It is a client-side pre-flight validation failure, so no request is ever sent to the PaddleOCR API. The error instance carries the offending path on its `path` property.
Source
Thrown at api_sdk/typescript/src/internal/http.ts:92
}
if (options.batchId !== undefined) {
body.batchId = options.batchId;
}
const data = await this.fetchJson<SubmitResponse>(this.jobsUrl, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
}, options.signal);
return requireJobId(data);
}
async submitFile(model: string, filePath: string, optionalPayload: object, options: SubmitOptions = {}): Promise<string> {
const fs = await import("fs");
const path = await import("path");
if (!fs.existsSync(filePath)) {
const { FileNotFoundError } = await import("../errors.js");
throw new FileNotFoundError(filePath);
}
const form = new FormData();
form.append("model", model);
form.append("optionalPayload", JSON.stringify(optionalPayload));
if (options.pageRanges !== undefined) {
form.append("pageRanges", options.pageRanges);
}
if (options.batchId !== undefined) {
form.append("batchId", options.batchId);
}
const fileBuffer = fs.readFileSync(filePath);
const blob = new Blob([fileBuffer]);
form.append("file", blob, path.basename(filePath));
const data = await this.fetchJson<SubmitResponse>(this.jobsUrl, {
method: "POST",View on GitHub (pinned to 2661c7c0ef)
Solutions
- Verify the path exists before calling submitFile: fs.existsSync(filePath) or fs.promises.access(filePath, fs.constants.R_OK)
- If the path is relative, resolve it against a known anchor: path.resolve(__dirname, 'assets/doc.pdf') instead of relying on cwd
- On Windows or cross-platform code, build paths with path.join()/path.resolve() rather than string concatenation
- If the file comes from async user input, await its write/download to complete before submitting
Example fix
// before
const jobId = await client.submitFile("PP-StructureV3", req.query.file, {});
// after
import fs from "node:fs";
const filePath = path.resolve(uploadsDir, req.query.file);
if (!fs.existsSync(filePath)) {
return res.status(400).send(`No such file: ${filePath}`);
}
const jobId = await client.submitFile("PP-StructureV3", filePath, {}); Defensive patterns
Strategy: validation
Validate before calling
import fs from "node:fs";
import path from "node:path";
function assertReadableFile(filePath: string): void {
const abs = path.resolve(filePath);
if (!fs.existsSync(abs)) throw new Error(`No such file: ${abs}`);
const stat = fs.statSync(abs);
if (!stat.isFile()) throw new Error(`Not a file: ${abs}`);
} Type guard
function isReadableFilePath(p: string): boolean {
try {
return fs.statSync(path.resolve(p)).isFile();
} catch {
return false;
}
} Try / catch
try {
await client.submitFile(model, filePath, payload);
} catch (e) {
if (e instanceof FileNotFoundError) {
// client-side: fix path or regenerate the file, do not retry as-is
throw new Error(`Input missing: ${e.path}`);
}
throw e;
} Prevention
- Resolve user-supplied paths with path.resolve against an explicit base directory, never process.cwd()
- Validate file existence and readability at the API boundary before enqueueing work
- If files arrive asynchronously, await the producing promise before submission
When it happens
Trigger: Calling client.submitFile(model, filePath, payload) (directly or via a higher-level extract/predict helper) where filePath points to a missing file: wrong relative path (resolved against process.cwd(), not the script), typo, file deleted between selection and upload, or a path from user input that was never validated.
Common situations: Running the SDK from a different working directory so relative paths break; paths built with manual '/' concatenation on Windows; files staged by an upstream process that has not finished writing; CI runners where the asset directory was not checked out.
Related errors
- Bad request: ${text}
- OCR pipeline config must be an object or YAML text.
- Worker transport client requires a createWorker() factory.
- destination is required.
- Destination parent must be a directory: {parent}
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/66394fa3cd331fd1.
Report an issue: GitHub.