Created
March 27, 2026 12:39
-
-
Save FlameWolf/e9fc523f7f78ed7c2819b0e8fcf09928 to your computer and use it in GitHub Desktop.
Hono: Validating & Procerssing Complex Schema Using MultiPart/Form-Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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