payloadcms/payload · error · APIError
No file data provided for import
Error message
No file data provided for import
What it means
Thrown by createImport when the `file` argument is missing or its `data` Buffer is falsy. The importer needs the raw bytes to parse CSV/JSON, so an empty/absent file is a hard 400. It is an APIError marked virtual (safe to surface to clients).
Source
Thrown at packages/plugin-import-export/src/import/createImport.ts:99
}
if (debug) {
req.payload.logger.debug({
collectionSlug,
format,
importMode,
matchField,
msg: 'Starting import process with args:',
transactionID: req.transactionID, // Log transaction ID to verify we're in same transaction
})
}
if (!collectionSlug) {
throw new APIError('Collection slug is required', 400, null, true)
}
if (!file || !file?.data) {
throw new APIError('No file data provided for import', 400, null, true)
}
if (debug) {
req.payload.logger.debug({
fileName: file.name,
fileSize: file.data.length,
mimeType: file.mimetype,
msg: 'File info',
})
}
const collectionConfig = req.payload.config.collections.find(
({ slug }) => slug === collectionSlug,
)
if (!collectionConfig) {
if (!collectionSlug) {
throw new APIError('Collection slug is required', 400, null, true)View on GitHub (pinned to 00c58b35c0)
Solutions
- Pass file: { data: Buffer, mimetype: string, name: string } to createImport.
- If invoking from a task, confirm getFileFromDoc returned a non-empty data Buffer before forwarding.
- In an HTTP handler, read the upload once into a Buffer and reuse it instead of piping it away.
Example fix
// before
await createImport({ collectionSlug: 'posts', format: 'csv', req })
// after
await createImport({
collectionSlug: 'posts',
format: 'csv',
file: { data: buffer, mimetype: 'text/csv', name: 'posts.csv' },
importMode: 'create',
req,
}) Defensive patterns
Strategy: validation
Validate before calling
function buildImportFile(data: unknown, mimetype: string, name: string) {
if (!Buffer.isBuffer(data) || data.length === 0) {
throw new Error('file.data must be a non-empty Buffer')
}
return { data: data as Buffer, mimetype, name }
}
// use before createImport
const file = buildImportFile(buf, 'text/csv', 'posts.csv')
await createImport({ ..., file }) Type guard
const isImportFile = (f: unknown): f is { data: Buffer; mimetype: string; name: string } =>
!!f &&
typeof f === 'object' &&
Buffer.isBuffer((f as { data?: unknown }).data) &&
(f as { data: Buffer }).data.length > 0 Prevention
- Read the upload into a Buffer once and reuse it; don't pipe it away before createImport.
- Type the file arg with the Import['file'] shape so missing data fails at compile time.
- In job/task code, assert getFileFromDoc returned data before forwarding to createImport.
When it happens
Trigger: Calling createImport({ ...args }) without a `file` field, or with file = { name, mimetype } but no `data`. Happens when an upstream caller (e.g. a job or custom endpoint) forgets to attach the parsed upload, or when a Buffer was already consumed by a prior stream read.
Common situations: A custom import endpoint reads req.file into a stream and forgets to keep a Buffer; a multipart parser drops the file under a size limit; migrating from a version where file was optional.
Related errors
- Unable to determine mimetype for file: ${importDoc.filename}
- Unable to determine mimetype for file: ${doc.filename}
- Unable to retrieve file: missing filename or url
- JSON import data must be an array of documents
- Invalid JSON format
AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12).
Data as JSON: /api/errors/387ce18ca506462a.
Report an issue: GitHub.