image validation using zod

i wrote this in the tRPC router but it gave this error

  createComic: protectedProcedure
    .input(
      z.object({
        title: z.string(),
        description: z.string(),
        coverImage: z
          .any()
          .refine((files) => files?.length == 1, "Image is required.")
          .refine(
            (files) => files?.[0]?.size <= MAX_FILE_SIZE,
            `Max file size is 5MB.`
          )
          .refine(
            (files) => ACCEPTED_IMAGE_TYPES.includes(files?.[0]?.type),
            ".jpg, .jpeg, .png and .webp files are accepted."
          ),
      })
    )
    .mutation(async ({ input, ctx }) => {
      const prisma = ctx.prisma;

      //upload to supabase
      const { data, error } = await ctx.supabase.storage
        .from("comic-cover")
        .upload(`comic-${input.title}.png`, input.coverImage, {
          cacheControl: "3600",
          upsert: false,
        });
      if (error) {
        throw new TRPCError({
          code: "INTERNAL_SERVER_ERROR",
          message: error.message,
        });
      }
      //get the url
      const { data: url } = ctx.supabase.storage
        .from("comic-cover")
        .getPublicUrl(data.path);

      const comic = await prisma.comic.create({
        data: {
          title: input.title,
          description: input.description,
          poster: url.publicUrl,
        },
      });
    }),
image.png
Was this page helpful?