zod validation with uploadthing and server actions
Does anyone know how i can handle with image upload to supabase. I have problem with zod schema with next js server action.
I have custom hook for upload image and saving file.url from uploadthing and first wanna check with like z.array(instanceof(File) then later have another images array where i save urls of images to db
I tried to make separated schema validation just for file and then merge with bigger schema to save all form in db but have conflict like having files array and dont have field prisma schema for that.
Tried also to set these merged schema only for useForm and resolver,set submit form function only sending values from bigger (main) schema but for some reason backend still get that files array and cant save it .
4 Replies
you can use next-safe-actions
i fixed it by adding onUpload directly after uploading images, but i tried to validate it with minimum 2 images and run action when submiting form before submitHandler function from react form state like this
and there is my action
but on submit i get this error
i dont understand what this means
as i said if i pass onUpload={uploadFiles} to direct upload on uploadthing after i upload files i can't validate this .min(2) because after upload my files array is empty