You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
portainer/app/react/components/form-components/yup-file-validation.ts

25 lines
490 B

import { mixed } from 'yup';
import { MixedSchema } from 'yup/lib/mixed';
type FileSchema = MixedSchema<File | undefined>;
export function file(): FileSchema {
return mixed();
}
export function withFileSize(fileValidation: FileSchema, maxSize: number) {
return fileValidation.test(
'fileSize',
'Selected file is too big.',
validateFileSize
);
function validateFileSize(file?: File) {
if (!file) {
return true;
}
return file.size <= maxSize;
}
}