Zod not validating file input
z.object({
userId: z.string(),
headerImage: z
.instanceof(File)
.refine((file) => {
return !file || file.size <= MAX_UPLOAD_SIZE;
}, "File size must be less than 2 MB")
.refine((file) => {
return ACCEPTED_FILE_TYPES.includes(file.type);
}, "File must be a PNG"),
// .any(),
}),z.object({
userId: z.string(),
headerImage: z
.instanceof(File)
.refine((file) => {
return !file || file.size <= MAX_UPLOAD_SIZE;
}, "File size must be less than 2 MB")
.refine((file) => {
return ACCEPTED_FILE_TYPES.includes(file.type);
}, "File must be a PNG"),
// .any(),
}),this is the zod schema but its throwing "Input not instance of File"
im checking that its a file on client also
function uploadFile(e: ChangeEvent<HTMLInputElement>) {
let file;
if (e.target.files) {
file = e.target.files[0];
}
if (file !== undefined) {
console.log(file);
mutate({ userId, headerImage: file });
}
}function uploadFile(e: ChangeEvent<HTMLInputElement>) {
let file;
if (e.target.files) {
file = e.target.files[0];
}
if (file !== undefined) {
console.log(file);
mutate({ userId, headerImage: file });
}
}