apache/answer · error
File validation failed
Error message
File validation failed
What it means
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.
Source
Thrown at ui/src/components/Editor/index.tsx:162
<div
className="d-flex justify-content-center align-items-center"
style={{ minHeight: '200px' }}>
<Spinner animation="border" variant="secondary" />
</div>
</div>
);
}
if (fullEditorPlugin) {
const FullEditorComponent = fullEditorPlugin.component;
const handleImageUpload = async (file: File | string): Promise<string> => {
if (typeof file === 'string') {
return file;
}
if (!verifyImageSize([file])) {
throw new Error('File validation failed');
}
return uploadSingleFile(file);
};
return (
<FullEditorComponent
value={value}
onChange={onChange}
onFocus={onFocus}
onBlur={onBlur}
placeholder={editorPlaceholder}
autoFocus={autoFocus}
imageUploadHandler={handleImageUpload}
uploadConfig={{
maxImageSizeMiB: max_image_size,
allowedExtensions: [
...authorized_image_extensions,View on GitHub (pinned to 3b9f137061)
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).
Example fix
// before
if (!verifyImageSize([file])) {
throw new Error('File validation failed');
}
// after
if (!verifyImageSize([file])) {
const resized = await resizeImage(file, { maxWidth: 1920, quality: 0.8 });
if (!verifyImageSize([resized])) {
throw new Error('File validation failed: image exceeds max size');
}
return uploadSingleFile(resized);
} Defensive patterns
Strategy: validation
Validate before calling
const MAX_IMAGE_BYTES = 5 * 1024 * 1024;
if (file instanceof File && file.size > MAX_IMAGE_BYTES) {
alert(`Image must be under ${MAX_IMAGE_BYTES / 1024 / 1024}MB`);
return;
} Type guard
function isFile(input: File | string): input is File {
return typeof input !== 'string' && input instanceof File;
} Try / catch
try {
const url = await handleImageUpload(file);
} catch (e) {
if (e instanceof Error && e.message === 'File validation failed') {
showUploadError('Image exceeds the allowed size. Please compress it first.');
} else throw e;
} Prevention
- 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
When it happens
Trigger: Selecting or pasting an image into the editor whose size exceeds the configured maximum (verifyImageSize([file]) returns false).
Common situations: 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.
Related errors
- unsupported image format: %s
- decode image config error: %v
- validate check exception
- base.request_format_error
- error.password.space_invalid
AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05).
Data as JSON: /api/errors/947edf4ca1d59219.
Report an issue: GitHub.