{"record":{"id":"8a05e527c30fd7da","repo":"payloadcms/payload","slug":"unable-to-determine-mimetype-for-file-doc-filen-8a05e5","errorCode":null,"errorMessage":"Unable to determine mimetype for file: ${doc.filename}","messagePattern":"Unable to determine mimetype for file: (.+?)","errorType":"http","errorClass":"FileRetrievalError","httpStatus":500,"severity":"error","filePath":"packages/plugin-import-export/src/utilities/getFileFromDoc.ts","lineNumber":48,"sourceCode":"  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)\n\n    // For relative URLs, construct a full URL using formatAdminURL which properly\n    // handles serverURL, basePath, and other config. This is important in job contexts\n    // where request headers may not be available for URL construction.\n    // Use serverURL from config, falling back to req.origin for local/job requests.\n    const fileUrl = doc.url.startsWith('http')","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/plugin-import-export/src/utilities/getFileFromDoc.ts#L30-L66","documentation":"On the local-storage branch, after getFileByPath succeeds, getFileFromDoc needs a mimetype from file.mimetype falling back to doc.mimeType. If neither is present it throws FileRetrievalError. The on-disk file was readable but carried no type information.","triggerScenarios":"The local file has no detectable mimetype and the doc lacks mimeType. getFileByPath's mimetype detection (usually extension-based) returned undefined.","commonSituations":"File written without an extension; extension not in the mimetype map; doc schema predates the mimeType field.","solutions":["Persist doc.mimeType on upload so the fallback resolves.","Ensure uploaded files retain their original extension so detection works.","Backfill mimeType for existing local files."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const mimetype = file.mimetype || doc.mimeType\nif (!mimetype) {\n  // derive from extension as a last resort, or fail fast with a clear message\n  throw new Error(`No mimetype for local file ${doc.filename}; set doc.mimeType`)\n}","typeGuard":"const hasAnyMimetype = (file: { mimetype?: unknown }, doc: { mimeType?: unknown }): boolean =>\n  typeof file.mimetype === 'string' || typeof doc.mimeType === 'string'","tryCatchPattern":null,"preventionTips":["Persist doc.mimeType so the local-file fallback always resolves.","Keep original file extensions so detection works.","Backfill mimeType for legacy local files."],"tags":["file-upload","mimetype","storage","plugin-import-export"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}