{"record":{"id":"3062433946de1853","repo":"payloadcms/payload","slug":"upload-collection-upload-collectionslug-was-not","errorCode":null,"errorMessage":"Upload collection ${upload.collectionSlug} was not found","messagePattern":"Upload collection (.+?) was not found","errorType":"http","errorClass":"APIError","httpStatus":400,"severity":"error","filePath":"packages/payload/src/uploads/endpoints/uploadInstructions.ts","lineNumber":45,"sourceCode":"  typeof upload.filesize === 'number' &&\n  Number.isSafeInteger(upload.filesize) &&\n  upload.filesize >= 0 &&\n  'mimeType' in upload &&\n  typeof upload.mimeType === 'string'\n\nexport const getUploadInstructions = async ({\n  overrideAccess = false,\n  req,\n  ...upload\n}: {\n  overrideAccess?: boolean\n  req: PayloadRequest\n} & UploadInstructionsRequest): Promise<UploadInstructions> => {\n  const collection = req.payload.collections[upload.collectionSlug]\n  const uploadInstructions = collection?.config?.upload?.uploadInstructions\n\n  if (!collection?.config?.upload) {\n    throw new APIError(`Upload collection ${upload.collectionSlug} was not found`, 400)\n  }\n\n  const filesizeLimit = req.payload.config.upload.limits?.fileSize\n  if (filesizeLimit && upload.filesize > filesizeLimit) {\n    throw new APIError(\n      `Exceeded file size limit. Limit: ${bytesToMB(filesizeLimit).toFixed(2)}MB, got: ${bytesToMB(upload.filesize).toFixed(2)}MB`,\n      400,\n    )\n  }\n\n  await checkFileRestrictions({\n    checkFileContents: false,\n    collection: collection.config,\n    file: {\n      name: upload.filename,\n      data: Buffer.alloc(0),\n      mimetype: upload.mimeType,\n      size: upload.filesize,","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/uploads/endpoints/uploadInstructions.ts#L27-L63","documentation":"APIError (HTTP 400) thrown by getUploadInstructions when req.payload.collections[collectionSlug] is missing OR exists but has no config.upload block. Used by the staged-upload flow: the client asks for upload instructions for a collection that is either not registered or not an upload collection.","triggerScenarios":"POST /api/payload/upload-instructions with a body whose collectionSlug is unknown to the server, or points to a collection defined without upload. The check `!collection?.config?.upload` covers both the missing-collection and missing-upload-block cases.","commonSituations":"Client sending a stale/wrong collection slug after a schema rename; frontend typo; collection added without the upload property; requesting staged upload instructions for a non-upload collection; mismatched collection slug between client and server Payload config.","solutions":["Confirm the collectionSlug in the request body exactly matches a registered upload collection's slug.","Add `upload: { staticDir: '...' }` to the named collection in your Payload config if it should accept uploads.","Sync the client's collection list with the server's after schema changes.","Validate the slug against req.payload.collections before invoking getUploadInstructions from custom code."],"exampleFix":"// client — before\nfetch('/api/payload/upload-instructions', { method: 'POST', body: JSON.stringify({ collectionSlug: 'media-files', filename, filesize, mimeType }) })\n// after — use the actual upload collection slug registered on the server\nfetch('/api/payload/upload-instructions', { method: 'POST', body: JSON.stringify({ collectionSlug: 'media', filename, filesize, mimeType }) })","handlingStrategy":"type-guard","validationCode":"const UPLOAD_SLUGS = Object.entries(payload.config.collections)\n  .filter(([, c]) => Boolean((c as any).upload))\n  .map(([slug]) => slug)\nfunction isValidUploadSlug(slug: string): boolean {\n  return UPLOAD_SLUGS.includes(slug)\n}\nif (!isValidUploadSlug(body.collectionSlug)) throw new Error('Unknown or non-upload collection')","typeGuard":"const isRegisteredUploadSlug = (slug: string, collections: Record<string, { upload?: unknown }>): boolean =>\n  Boolean(collections[slug]?.upload)","tryCatchPattern":"try {\n  await fetch('/api/payload/upload-instructions', { method: 'POST', body: JSON.stringify(body) })\n} catch (e) {\n  if (/Upload collection .* was not found/.test(e.message)) alert('Unknown upload collection slug')\n}","preventionTips":["Derive the slug list from server config and share it with the client.","After schema renames, ship a client build that updates the slug list.","Validate the slug against the live collections before the request.","Use TypeScript union types for collection slugs to catch typos at compile time."],"tags":["upload","api","config","staged-upload","validation"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}