{"record":{"id":"76091de0e08d842b","repo":"payloadcms/payload","slug":"file-not-found-at-path-filepath","errorCode":null,"errorMessage":"File not found at path: ${filePath}","messagePattern":"File not found at path: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/plugin-import-export/src/utilities/getFileFromDoc.ts","lineNumber":42,"sourceCode":" * - For cloud storage: fetches via Payload's file endpoint, which triggers\n *   the storage adapter's staticHandler to serve the file\n */\nexport const getFileFromDoc = async ({ collectionConfig, doc, req }: Args): Promise<Result> => {\n  const uploadConfig: UploadConfig =\n    typeof collectionConfig.upload === 'object' ? collectionConfig.upload : {}\n  const disableLocalStorage = uploadConfig.disableLocalStorage ?? false\n  const staticDir = uploadConfig.staticDir || collectionConfig.slug\n\n  const serverURL = req.payload.config.serverURL\n  const isLocalFile = (serverURL && doc.url?.startsWith(serverURL)) || doc.url?.startsWith('/')\n\n  if (!disableLocalStorage && isLocalFile && doc.filename) {\n    // Local storage enabled - read directly from disk (efficient, no HTTP roundtrip)\n    const filePath = `${staticDir}/${doc.filename}`\n    const file = await getFileByPath(filePath)\n\n    if (!file) {\n      throw new Error(`File not found at path: ${filePath}`)\n    }\n\n    const mimetype = file.mimetype || doc.mimeType\n\n    if (!mimetype) {\n      throw new FileRetrievalError(req.t, `Unable to determine mimetype for file: ${doc.filename}`)\n    }\n\n    return {\n      data: file.data,\n      mimetype,\n    }\n  }\n\n  if (doc.filename && doc.url) {\n    // Cloud storage or external - fetch via Payload's file endpoint\n    // getExternalFile constructs full URL, includes cookies for auth, and\n    // the request goes through Payload's handler chain (including storage adapter)","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/plugin-import-export/src/utilities/getFileFromDoc.ts#L24-L60","documentation":"getFileFromDoc reads local files from disk via getFileByPath(`${staticDir}/${filename}`). If that returns null (file absent on disk) it throws a plain Error with the resolved path. staticDir defaults to the collection slug when uploadConfig.staticDir is unset.","triggerScenarios":"The file referenced by the doc is not present on disk: deleted, moved during migration, never written, or staticDir points to the wrong directory. The doc.url must look local (starts with serverURL or '/') to reach this branch.","commonSituations":"Volume not mounted in a new environment; files migrated to cloud storage but DB rows still reference local URLs; staticDir changed (e.g. collection renamed) leaving orphan paths.","solutions":["Confirm the file exists at the resolved `${staticDir}/${filename}` path on the running host.","Verify uploadConfig.staticDir matches where files are actually written.","If files moved to cloud storage, update doc.url so isLocalFile is false and the cloud branch is used."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { existsSync } from 'fs'\nconst staticDir = uploadConfig.staticDir || collectionConfig.slug\nconst filePath = `${staticDir}/${doc.filename}`\nif (!existsSync(filePath)) {\n  throw new Error(`Local file missing on disk: ${filePath}`)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep uploadConfig.staticDir stable; if you change it, migrate existing files.","Mount the storage volume in every environment that runs imports.","When migrating to cloud storage, update doc.url so the local branch is skipped."],"tags":["storage","file-system","import","plugin-import-export"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}