Handling multipart requests with schemas can indeed be a bit tricky. In your case, you need to in...

How to handle multipart requests?

I have a schema like this:

export const ToolSubmissionFormSchema = {
 name: Schema.String.pipe(
   Schema.nonEmptyString({
     message: () => "Name is required.",
   })
 ),


 logo: Schema.instanceOf(File)
   .annotations({ message: () => "Logo is required." })
   .pipe(
     Schema.filter(
       (file) => file.size <= LOGO_MAX_SIZE_MB * 1024 * 1024,
       {
         message: () =>
           `Logo must be less than ${LOGO_MAX_SIZE_MB}MB`,
       }
     )
   ),
};


}).pipe(Schema.annotations({ parseOptions: { errors: "all" } }));


In the backend, I have this endpoint:

import { HttpApiEndpoint, HttpApiSchema, Multipart } from "@effect/platform";
import { Schema } from "effect";
import { ToolSubmissionFormSchema } from "@/lib/schema";

export const submitTool = HttpApiEndpoint.post("submitTool", "/submit")
  .setPayload(
    HttpApiSchema.Multipart(
      Schema.Struct({
        files: Multipart.FilesSchema,
      })
    )
  )
  .addSuccess(Schema.Struct({ message: Schema.String }));


In the docs, it says, I need to define a files filed, which I have done, but where do I mention the ToolSubmissionFormSchema?

It s very confusing.
Was this page helpful?