{"record":{"id":"947edf4ca1d59219","repo":"apache/answer","slug":"file-validation-failed","errorCode":null,"errorMessage":"File validation failed","messagePattern":"File validation failed","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ui/src/components/Editor/index.tsx","lineNumber":162,"sourceCode":"        <div\n          className=\"d-flex justify-content-center align-items-center\"\n          style={{ minHeight: '200px' }}>\n          <Spinner animation=\"border\" variant=\"secondary\" />\n        </div>\n      </div>\n    );\n  }\n\n  if (fullEditorPlugin) {\n    const FullEditorComponent = fullEditorPlugin.component;\n\n    const handleImageUpload = async (file: File | string): Promise<string> => {\n      if (typeof file === 'string') {\n        return file;\n      }\n\n      if (!verifyImageSize([file])) {\n        throw new Error('File validation failed');\n      }\n\n      return uploadSingleFile(file);\n    };\n\n    return (\n      <FullEditorComponent\n        value={value}\n        onChange={onChange}\n        onFocus={onFocus}\n        onBlur={onBlur}\n        placeholder={editorPlaceholder}\n        autoFocus={autoFocus}\n        imageUploadHandler={handleImageUpload}\n        uploadConfig={{\n          maxImageSizeMiB: max_image_size,\n          allowedExtensions: [\n            ...authorized_image_extensions,","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/apache/answer/blob/3b9f1370612e690a0b7f230f05e688930db4c6d3/ui/src/components/Editor/index.tsx#L144-L180","documentation":"handleImageUpload in the Editor validates each uploaded file with verifyImageSize before pushing it to the upload endpoint. If the file exceeds the allowed image size limits, it throws 'File validation failed' and the upload is aborted.","triggerScenarios":"Selecting or pasting an image into the editor whose size exceeds the configured maximum (verifyImageSize([file]) returns false).","commonSituations":"Users uploading multi-megabyte screenshots or photos; deployments where the admin lowered the upload size limit; client-side limit out of sync with server-side limit so large files get rejected in the browser before reaching the API.","solutions":["Compress or resize the image before uploading (e.g. canvas downscale) so it passes verifyImageSize.","Pick a smaller file and retry.","If the limit is too strict, raise the site upload size configuration in the admin settings (and the corresponding server limit)."],"exampleFix":"// before\nif (!verifyImageSize([file])) {\n  throw new Error('File validation failed');\n}\n// after\nif (!verifyImageSize([file])) {\n  const resized = await resizeImage(file, { maxWidth: 1920, quality: 0.8 });\n  if (!verifyImageSize([resized])) {\n    throw new Error('File validation failed: image exceeds max size');\n  }\n  return uploadSingleFile(resized);\n}","handlingStrategy":"validation","validationCode":"const MAX_IMAGE_BYTES = 5 * 1024 * 1024;\nif (file instanceof File && file.size > MAX_IMAGE_BYTES) {\n  alert(`Image must be under ${MAX_IMAGE_BYTES / 1024 / 1024}MB`);\n  return;\n}","typeGuard":"function isFile(input: File | string): input is File {\n  return typeof input !== 'string' && input instanceof File;\n}","tryCatchPattern":"try {\n  const url = await handleImageUpload(file);\n} catch (e) {\n  if (e instanceof Error && e.message === 'File validation failed') {\n    showUploadError('Image exceeds the allowed size. Please compress it first.');\n  } else throw e;\n}","preventionTips":["Set the accept and size checks on the file input before opening the picker","Compress client-side (canvas) before upload","Keep client and server upload limits in sync","Show clear UI feedback about the allowed size"],"tags":["validation","file-upload","image"],"backgroundTag":"file-validation-failed","analyzedSha":"3b9f1370612e690a0b7f230f05e688930db4c6d3","analyzedAt":"2026-09-05T18:18:39.533Z","contentChangedAt":"2026-09-05T18:18:39.533Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}