79316438

Date: 2024-12-29 22:22:47
Score: 1
Natty:
Report link

if you're facing the same issue, here is a workout that works for me:

image: z
    .union([
      z
        .instanceof(File, { message: "Image is required" })
        .refine(
          (file) => !file || file.size !== 0 || file.size <= 5000000,
          `Max image size is ${5000000}MB`
        )
        .refine(
          (file) =>
            !file ||
            file.type === "" ||
            ["image/jpeg", "image/png", "image/jpg"].includes(file.type),
          "Only .jpg, .jpeg, and .png formats are supported"
        ),
      z.string().optional(), // Allow the existing image URL for editing mode
    ])
    .refine((value) => value instanceof File || typeof value === "string", {
      message: "Image is required",
    }),
Reasons:
  • Whitelisted phrase (-1): works for me
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): facing the same issue
  • Low reputation (0.5):
Posted by: Vicheans