{"record":{"id":"3dfeff91751a0377","repo":"payloadcms/payload","slug":"unable-to-determine-mimetype-for-file-importdoc","errorCode":null,"errorMessage":"Unable to determine mimetype for file: ${importDoc.filename}","messagePattern":"Unable to determine mimetype for file: (.+?)","errorType":"exception","errorClass":"FileRetrievalError","httpStatus":null,"severity":"error","filePath":"packages/plugin-import-export/src/import/getCreateImportCollectionTask.ts","lineNumber":72,"sourceCode":"      if (!collectionConfig) {\n        throw new Error(`Collection config not found for: ${importCollection}`)\n      }\n\n      // Retrieve the file using getFileFromDoc (handles both local and cloud storage)\n      const file = await getFileFromDoc({\n        collectionConfig,\n        doc: {\n          filename: importDoc.filename as string,\n          mimeType: importDoc.mimeType as string | undefined,\n          url: importDoc.url as string | undefined,\n        },\n        req,\n      })\n\n      const fileMimetype = file.mimetype || (importDoc.mimeType as string)\n\n      if (!fileMimetype) {\n        throw new FileRetrievalError(\n          req.t,\n          `Unable to determine mimetype for file: ${importDoc.filename}`,\n        )\n      }\n\n      const result = await createImport({\n        name: (importDoc.filename as string) || 'import',\n        batchSize,\n        collectionSlug: importDoc.collectionSlug as string,\n        debug,\n        defaultVersionStatus,\n        file: {\n          name: importDoc.filename as string,\n          data: file.data,\n          mimetype: fileMimetype,\n        },\n        format: fileMimetype === 'text/csv' ? 'csv' : 'json',\n        importMode: (importDoc.importMode as 'create' | 'update' | 'upsert') || 'create',","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/plugin-import-export/src/import/getCreateImportCollectionTask.ts#L54-L90","documentation":"After retrieving the file, the createCollectionImport task derives a mimetype from file.mimetype falling back to importDoc.mimeType. If both are falsy it throws a FileRetrievalError, because the mimetype is required to route CSV vs JSON parsing.","triggerScenarios":"The stored import document has no mimeType field and the retrieved file's mimetype is undefined. Common when uploads were persisted without a mimeType or a storage adapter did not populate it.","commonSituations":"Older import records created before mimeType was tracked; custom upload flow that omits mimeType; storage adapter that strips metadata.","solutions":["Backfill importDoc.mimeType for existing records.","Ensure new uploads persist mimeType (set it in the upload handler / collection fields).","If the file is local, confirm getFileByPath returns a mimetype (depends on the file extension detection)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const importDoc = await req.payload.findByID({ id: importId, collection: importCollection })\nif (!importDoc) throw new Error('import doc missing')\nconst mimetype = (await getFileFromDoc({ collectionConfig, doc: importDoc, req })).mimetype || importDoc.mimeType\nif (!mimetype) throw new Error('no mimetype; backfill importDoc.mimeType')","typeGuard":"const hasMimeType = (d: { mimeType?: unknown }): boolean =>\n  typeof d.mimeType === 'string' && d.mimeType.length > 0","tryCatchPattern":null,"preventionTips":["Persist mimeType on every upload to the imports collection.","Backfill mimeType for legacy records before running imports.","Confirm getFileByPath/getExternalFile return mimetype for your storage adapter."],"tags":["file-upload","import","mimetype","plugin-import-export"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}