{"record":{"id":"387ce18ca506462a","repo":"payloadcms/payload","slug":"no-file-data-provided-for-import","errorCode":null,"errorMessage":"No file data provided for import","messagePattern":"No file data provided for import","errorType":"http","errorClass":"APIError","httpStatus":400,"severity":"error","filePath":"packages/plugin-import-export/src/import/createImport.ts","lineNumber":99,"sourceCode":"  }\n\n  if (debug) {\n    req.payload.logger.debug({\n      collectionSlug,\n      format,\n      importMode,\n      matchField,\n      msg: 'Starting import process with args:',\n      transactionID: req.transactionID, // Log transaction ID to verify we're in same transaction\n    })\n  }\n\n  if (!collectionSlug) {\n    throw new APIError('Collection slug is required', 400, null, true)\n  }\n\n  if (!file || !file?.data) {\n    throw new APIError('No file data provided for import', 400, null, true)\n  }\n\n  if (debug) {\n    req.payload.logger.debug({\n      fileName: file.name,\n      fileSize: file.data.length,\n      mimeType: file.mimetype,\n      msg: 'File info',\n    })\n  }\n\n  const collectionConfig = req.payload.config.collections.find(\n    ({ slug }) => slug === collectionSlug,\n  )\n\n  if (!collectionConfig) {\n    if (!collectionSlug) {\n      throw new APIError('Collection slug is required', 400, null, true)","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/plugin-import-export/src/import/createImport.ts#L81-L117","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nawait createImport({ collectionSlug: 'posts', format: 'csv', req })\n// after\nawait createImport({\n  collectionSlug: 'posts',\n  format: 'csv',\n  file: { data: buffer, mimetype: 'text/csv', name: 'posts.csv' },\n  importMode: 'create',\n  req,\n})","handlingStrategy":"validation","validationCode":"function buildImportFile(data: unknown, mimetype: string, name: string) {\n  if (!Buffer.isBuffer(data) || data.length === 0) {\n    throw new Error('file.data must be a non-empty Buffer')\n  }\n  return { data: data as Buffer, mimetype, name }\n}\n\n// use before createImport\nconst file = buildImportFile(buf, 'text/csv', 'posts.csv')\nawait createImport({ ..., file })","typeGuard":"const isImportFile = (f: unknown): f is { data: Buffer; mimetype: string; name: string } =>\n  !!f &&\n  typeof f === 'object' &&\n  Buffer.isBuffer((f as { data?: unknown }).data) &&\n  (f as { data: Buffer }).data.length > 0","tryCatchPattern":null,"preventionTips":["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."],"tags":["import","validation","file-upload","plugin-import-export"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}