{"record":{"id":"4407f48bf552b512","repo":"danny-avila/LibreChat","slug":"image-validation-failed-for-file-filename-va","errorCode":null,"errorMessage":"Image validation failed for ${file.filename}: ${validation.error}","messagePattern":"Image validation failed for (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"api/server/services/Files/images/encode.js","lineNumber":214,"sourceCode":"      continue;\n    }\n\n    /** Validate image buffer against size limits */\n    if (file.height && file.width) {\n      const imageBuffer = imageContent.startsWith('http')\n        ? null\n        : Buffer.from(imageContent, 'base64');\n\n      if (imageBuffer) {\n        const validation = await validateImage(\n          imageBuffer,\n          imageBuffer.length,\n          effectiveEndpoint,\n          configuredFileSizeLimit,\n        );\n\n        if (!validation.isValid) {\n          throw new Error(`Image validation failed for ${file.filename}: ${validation.error}`);\n        }\n      }\n    }\n\n    const imagePart = {\n      type: ContentTypes.IMAGE_URL,\n      image_url: {\n        url: imageContent.startsWith('http')\n          ? imageContent\n          : `data:${file.type};base64,${imageContent}`,\n        detail,\n      },\n    };\n\n    if (mode === VisionModes.agents) {\n      result.image_urls.push({ ...imagePart });\n      result.files.push({ ...fileMetadata });\n      continue;","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/danny-avila/LibreChat/blob/5ff282f9006c436e561de1afd39a481bea1ef0d8/api/server/services/Files/images/encode.js#L196-L232","documentation":"Thrown in encode.js when validateImage() — which checks format, dimensions, byte size against the configured file size limit, and (if configured) endpoint-specific policy — returns `{ isValid: false }` for an image buffer about to be embedded as an image_url part. The wrapped `validation.error` carries the specific failure reason from the validator.","triggerScenarios":"An image attachment's buffer fails format detection (not a real image), exceeds the configured file size limit, exceeds the endpoint's max dimensions, or matches a disallowed MIME type for the active endpoint (`effectiveEndpoint`). Validation runs only when an `imageBuffer` was decoded from base64 — URL-only image parts skip this branch.","commonSituations":"A user uploads a file with an `.png` extension that is actually a PDF or a renamed executable; the admin lowered FILE_SIZE_LIMIT after larger images were accepted; a model endpoint configured with stricter dimension limits than the global default; a corrupt image that sharp cannot parse.","solutions":["Inspect `validation.error` for the specific reason (size, format, dimensions) and address that root cause.","Reduce the image's bytes or dimensions before upload (compress/resize client-side).","Confirm the file is a real image (`file` command on the upload) and not a renamed binary.","If the limit is wrong, update the relevant FILE_SIZE_LIMIT / endpoint image config rather than disabling validation."],"exampleFix":"// before: validation surfaces generic\nif (!validation.isValid) throw new Error(...);\n\n// after: branch on the specific reason\nif (!validation.isValid) {\n  if (validation.error?.includes('size')) return res.status(413).json({ error: 'Image too large; max 5 MB.' });\n  if (validation.error?.includes('format')) return res.status(415).json({ error: 'Unsupported image format.' });\n  return res.status(422).json({ error: validation.error });\n}","handlingStrategy":"validation","validationCode":"// Run the same validator before embedding\nconst v = await validateImage(buffer, buffer.length, endpoint, configuredLimit);\nif (!v.isValid) {\n  return res.status(422).json({ error: `Image rejected: ${v.error}` });\n}","typeGuard":null,"tryCatchPattern":"try { await encodeAttachments(parts); }\ncatch (e) {\n  if (/Image validation failed/.test(e.message)) {\n    return res.status(422).json({ error: e.message });\n  }\n  throw e;\n}","preventionTips":["Validate file size and dimensions on the client before upload.","Confirm files are real images (magic-byte check) regardless of extension.","Keep endpoint-specific size limits aligned with the global FILE_SIZE_LIMIT."],"tags":["image","validation","upload","encode"],"backgroundTag":null,"analyzedSha":"5ff282f9006c436e561de1afd39a481bea1ef0d8","analyzedAt":"2026-08-12T21:38:08.145Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}