{"record":{"id":"217b643924e7270c","repo":"payloadcms/payload","slug":"invalid-upload-collection","errorCode":null,"errorMessage":"Invalid upload collection.","messagePattern":"Invalid upload collection\\.","errorType":"exception","errorClass":"APIError","httpStatus":400,"severity":"error","filePath":"packages/payload/src/utilities/addDataAndFileToRequest.ts","lineNumber":78,"sourceCode":"      }\n\n      if (!req.file && fields?.file && typeof fields?.file === 'string') {\n        let uploadedFile: UploadInstructions['file']\n        try {\n          uploadedFile = JSON.parse(fields.file)\n        } catch {\n          throw new APIError('A file name is required.', 400)\n        }\n        const collectionSlug =\n          typeof req.routeParams?.collection === 'string'\n            ? req.routeParams.collection\n            : uploadedFile.collectionSlug\n        const uploadConfig = collectionSlug\n          ? req.payload.collections[collectionSlug]?.config.upload\n          : undefined\n\n        if (!collectionSlug || !uploadConfig) {\n          throw new APIError('Invalid upload collection.', 400)\n        }\n\n        req.file = await getFileFromUploadInstructions({\n          collectionSlug,\n          file: uploadedFile,\n          req,\n        })\n      }\n    }\n  }\n}\n","sourceCodeStart":60,"sourceCodeEnd":90,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/payload/src/utilities/addDataAndFileToRequest.ts#L60-L90","documentation":"Thrown when the collection slug resolved for a staged upload either is empty or does not correspond to a collection with an `upload` config. Payload checks `req.payload.collections[collectionSlug]?.config.upload` and requires both a slug and a truthy upload config.","triggerScenarios":"The `file` JSON object `collectionSlug` is missing/empty AND the request route does not provide a collection param; or the resolved slug refers to a collection that has no `upload` property (i.e. it is not an upload-enabled collection).","commonSituations":"Sending a staged-upload `file` instruction for a collection that is not configured with `upload: { ... }`; the `collectionSlug` in the instruction JSON is misspelled or refers to a non-upload collection; the request is hitting a generic route without a collection route param and the instruction omits `collectionSlug`.","solutions":["Ensure the target collection has `upload` enabled in its config.","Verify the `collectionSlug` in the `file` instruction matches a registered upload collection slug exactly.","If the request is to a collection-specific route, confirm the route param resolves correctly; otherwise include `collectionSlug` in the instruction JSON.","Check for slug casing / naming mismatches between client and server config."],"exampleFix":"// before -- collection has no upload config\nconst mediaCollection = { slug: 'media', fields: [...] }\n// client sends file instruction with collectionSlug: 'media'\n\n// after\nconst mediaCollection = {\n  slug: 'media',\n  upload: { staticDir: 'media', imageSizes: [...] },\n  fields: [...],\n}","handlingStrategy":"validation","validationCode":"// Verify the collection exists and has upload enabled before sending\nconst slug = 'media'\nconst collection = payloadConfig.collections.find(c => c.slug === slug)\nif (!collection?.upload) {\n  throw new Error(`Collection '${slug}' is not an upload collection`)\n}","typeGuard":"const isUploadCollection = (c) => !!c && c.upload !== undefined","tryCatchPattern":"try {\n  await fetch(url, { method: 'POST', body: formData })\n} catch (e) {\n  if (e instanceof APIError && e.message === 'Invalid upload collection.') {\n    // verify collectionSlug is correct and upload is enabled in config\n  } else throw e\n}","preventionTips":["Confirm the target collection has upload: { ... } in its config.","Verify the collectionSlug in the file instruction matches a registered upload collection.","Check slug casing -- collection slugs are case-sensitive."],"tags":["upload","collection","config","validation"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}