payloadcms/payload · error · FileRetrievalError
Unable to determine mimetype for file: ${importDoc.filename}
Error message
Unable to determine mimetype for file: ${importDoc.filename} What it means
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.
Source
Thrown at packages/plugin-import-export/src/import/getCreateImportCollectionTask.ts:72
if (!collectionConfig) {
throw new Error(`Collection config not found for: ${importCollection}`)
}
// Retrieve the file using getFileFromDoc (handles both local and cloud storage)
const file = await getFileFromDoc({
collectionConfig,
doc: {
filename: importDoc.filename as string,
mimeType: importDoc.mimeType as string | undefined,
url: importDoc.url as string | undefined,
},
req,
})
const fileMimetype = file.mimetype || (importDoc.mimeType as string)
if (!fileMimetype) {
throw new FileRetrievalError(
req.t,
`Unable to determine mimetype for file: ${importDoc.filename}`,
)
}
const result = await createImport({
name: (importDoc.filename as string) || 'import',
batchSize,
collectionSlug: importDoc.collectionSlug as string,
debug,
defaultVersionStatus,
file: {
name: importDoc.filename as string,
data: file.data,
mimetype: fileMimetype,
},
format: fileMimetype === 'text/csv' ? 'csv' : 'json',
importMode: (importDoc.importMode as 'create' | 'update' | 'upsert') || 'create',View on GitHub (pinned to 00c58b35c0)
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).
Defensive patterns
Strategy: validation
Validate before calling
const importDoc = await req.payload.findByID({ id: importId, collection: importCollection })
if (!importDoc) throw new Error('import doc missing')
const mimetype = (await getFileFromDoc({ collectionConfig, doc: importDoc, req })).mimetype || importDoc.mimeType
if (!mimetype) throw new Error('no mimetype; backfill importDoc.mimeType') Type guard
const hasMimeType = (d: { mimeType?: unknown }): boolean =>
typeof d.mimeType === 'string' && d.mimeType.length > 0 Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Older import records created before mimeType was tracked; custom upload flow that omits mimeType; storage adapter that strips metadata.
Related errors
- Unable to determine mimetype for file: ${doc.filename}
- No file data provided for import
- Unable to determine mimetype for file: ${doc.filename}
- Unable to retrieve file: missing filename or url
- Collection with slug ${collectionSlug} not found
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/3dfeff91751a0377.
Report an issue: GitHub.