{"record":{"id":"4f6e777f662493a4","repo":"payloadcms/payload","slug":"unable-to-determine-mimetype-for-file-doc-filen","errorCode":null,"errorMessage":"Unable to determine mimetype for file: ${doc.filename}","messagePattern":"Unable to determine mimetype for file: (.+?)","errorType":"http","errorClass":"FileRetrievalError","httpStatus":500,"severity":"error","filePath":"packages/plugin-import-export/src/import/getImportCollection.ts","lineNumber":111,"sourceCode":"    }\n\n    if (!disableJobsQueue) {\n      return doc\n    }\n\n    try {\n      // Get file data from the uploaded document\n      // First try req.file which is available during the same request (especially important for cloud storage)\n      // Fall back to getFileFromDoc for cases where req.file isn't available\n      let fileData: Buffer\n      let fileMimetype: string\n\n      if (req.file?.data) {\n        fileData = req.file.data\n        fileMimetype = req.file.mimetype || doc.mimeType\n\n        if (!fileMimetype) {\n          throw new FileRetrievalError(\n            req.t,\n            `Unable to determine mimetype for file: ${doc.filename}`,\n          )\n        }\n      } else {\n        const fileFromDoc = await getFileFromDoc({\n          collectionConfig,\n          doc: {\n            filename: doc.filename,\n            mimeType: doc.mimeType,\n            url: doc.url,\n          },\n          req,\n        })\n        fileData = fileFromDoc.data\n        fileMimetype = fileFromDoc.mimetype\n      }\n","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/plugin-import-export/src/import/getImportCollection.ts#L93-L129","documentation":"In the synchronous import path (getImportCollection with disableJobsQueue), the hook prefers req.file.data. It derives the mimetype from req.file.mimetype falling back to doc.mimeType; if both are absent it throws FileRetrievalError before parsing.","triggerScenarios":"An upload arrives where req.file has data but no mimetype, and the persisted doc also lacks mimeType. Typical of direct API uploads that omit the multipart mimetype or a doc schema without a mimeType field.","commonSituations":"Custom API client posting a file without a Content-Type part; cloud-storage path where req.file isn't populated and doc.mimeType was never set.","solutions":["Ensure the upload includes a mimetype so req.file.mimetype is set.","Persist doc.mimeType on the imports collection and backfill existing docs.","If using cloud storage, verify the doc has mimeType before the sync hook runs."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const fileMimetype = req.file?.mimetype || doc.mimeType\nif (req.file?.data && !fileMimetype) {\n  throw new Error('Upload has no mimetype and doc.mimeType is unset')\n}","typeGuard":"const uploadHasMimetype = (req: PayloadRequest, doc: { mimeType?: unknown }): boolean =>\n  !!(req.file?.mimetype || doc.mimeType)","tryCatchPattern":null,"preventionTips":["Require a Content-Type on the multipart part that creates the import upload.","Populate doc.mimeType in an afterChange hook if missing.","For cloud storage, set the object's Content-Type at write time."],"tags":["file-upload","import","mimetype","hooks","plugin-import-export"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}