Skip to content

Instantly share code, notes, and snippets.

@FlameWolf
Created March 27, 2026 12:39
Show Gist options
  • Select an option

  • Save FlameWolf/e9fc523f7f78ed7c2819b0e8fcf09928 to your computer and use it in GitHub Desktop.

Select an option

Save FlameWolf/e9fc523f7f78ed7c2819b0e8fcf09928 to your computer and use it in GitHub Desktop.
Hono: Validating & Procerssing Complex Schema Using MultiPart/Form-Data
const postCreateReqType = type({
content: "string",
media: type("string")
.configure({
format: "binary"
})
.or("File"),
poll: type("string").pipe(
value =>
JSON.parse(value) as {
first: string;
second: string;
}
)
});
app.post("/create-post", validator("form", postCreateReqType), async ctx => {
const reqBody = ctx.req.valid("form");
var fileContent = await (reqBody.media as File).text();
return ctx.json(Object.assign(reqBody, { fileContent }));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment