{"record":{"id":"ec803e4b700e12d2","repo":"payloadcms/payload","slug":"no-files-were-uploaded","errorCode":null,"errorMessage":"No files were uploaded.","messagePattern":"No files were uploaded\\.","errorType":"http","errorClass":"MissingFile","httpStatus":400,"severity":"error","filePath":"packages/payload/src/uploads/generateFileData.ts","lineNumber":156,"sourceCode":"        file = await getExternalFile({\n          data: incomingFileData as unknown as FileData,\n          req,\n          uploadConfig: collectionConfig.upload,\n        })\n        overwriteExistingFiles = true\n      }\n    } catch (err: unknown) {\n      throw new FileRetrievalError(req.t, err instanceof Error ? err.message : undefined)\n    }\n  }\n\n  if (isDuplicating) {\n    overwriteExistingFiles = false\n  }\n\n  if (!file) {\n    if (throwOnMissingFile) {\n      throw new MissingFile(req.t)\n    }\n\n    return {\n      data: incomingFileData!,\n      files: [],\n    }\n  }\n\n  await checkFileRestrictions({\n    collection: collectionConfig,\n    file,\n    req,\n  })\n\n  if (!disableLocalStorage) {\n    await fs.mkdir(staticPath!, { recursive: true })\n  }\n","sourceCodeStart":138,"sourceCodeEnd":174,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/uploads/generateFileData.ts#L138-L174","documentation":"`generateFileData` resolves the file to process from `req.file`, duplication, or re-upload. If after all of those checks `file` is still falsy and the caller passed `throwOnMissingFile: true`, Payload throws `MissingFile` (HTTP 400, message `No files were uploaded.`). When `throwOnMissingFile` is false, the function instead returns the incoming data with an empty `files` array (a no-op update).","triggerScenarios":"A create/update operation on an upload collection where `req.file` is undefined, the operation is not a duplication, `shouldReupload` is false (no upload edits), and the collection/operation was configured with `throwOnMissingFile: true`. Payload's collection create flow sets this true when `filesRequiredOnCreate` is in effect; updates typically pass it based on whether a file is required.","commonSituations":"Creating a document on an upload collection without attaching a file (default `filesRequiredOnCreate` is true). A multipart parser misconfigured so `req.file` is never populated. The client sent JSON only, omitting the file part. An update was expected to attach a new file but the form had no file field.","solutions":["Attach a file to the request (`multipart/form-data` with the file part) when creating on an upload collection.","If the collection should allow file-less creates, set `upload.filesRequiredOnCreate: false`.","Ensure your HTTP layer (formidable/busboy/Next.js route) actually populates `req.file` from the multipart body.","For updates that legitimately change only metadata, confirm the operation is `update` and not flagged to require a file."],"exampleFix":"// before — creating an upload doc without a file\nawait payload.create({\n  collection: 'media',\n  data: { alt: 'no file attached' },\n})\n\n// after — either attach a file or relax the requirement\nconst form = new FormData()\nform.append('file', fileBlob, 'photo.png')\nform.append('alt', 'caption')\nawait fetch(`${url}/api/media`, { method: 'POST', body: form })\n\n// OR disable the requirement\nconst Media = { slug: 'media', upload: { filesRequiredOnCreate: false } }","handlingStrategy":"validation","validationCode":"function hasFile(file: unknown): boolean {\n  return !!file && (typeof (file as any).data !== 'undefined' || typeof (file as any).tempFilePath === 'string')\n}\n\nif (!hasFile(req.file)) {\n  if (collection.upload?.filesRequiredOnCreate === false) {\n    // proceed without a file\n  } else {\n    throw new Error('A file is required to create on this upload collection')\n  }\n}","typeGuard":"function hasAttachedFile(file: unknown): file is { data: Buffer; name: string; mimetype: string; size: number } {\n  return !!file && typeof file === 'object' &&\n    typeof (file as any).name === 'string' &&\n    (Buffer.isBuffer((file as any).data) || typeof (file as any).tempFilePath === 'string')\n}","tryCatchPattern":"try {\n  await payload.create({ collection: 'media', data, file })\n} catch (err) {\n  if (err instanceof Error && /no files were uploaded/i.test(err.message)) {\n    if (allowFileless) {\n      // set upload.filesRequiredOnCreate: false and retry\n    } else {\n      // prompt the user to attach a file\n    }\n  } else throw err\n}","preventionTips":["Attach a real file part on creates against upload collections.","Set `upload.filesRequiredOnCreate: false` if file-less creates are valid.","Verify your multipart handler populates `req.file`."],"tags":["upload","missing-file","validation","create"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}