A minimal multipart middleware for chubbyts-undici-server.
npm install @chubbyts/chubbyts-undici-multipart














A minimal multipart middleware for chubbyts-undici-server.
* node: 20
* [@chubbyts/chubbyts-undici-server][2]: ^1.0.0
* [busboy][3]: ^1.6.0
Through NPM as [@chubbyts/chubbyts-undici-multipart][1].
``sh`
npm i @chubbyts/chubbyts-undici-multipart@^1.0.0
`ts
import { createMultipartMiddleware } from '@chubbyts/chubbyts-undici-multipart/dist/multipart-middleware';
import type { Handler } from '@chubbyts/chubbyts-undici-server/dist/handler';
import { ServerRequest } from '@chubbyts/chubbyts-undici-server/dist/server';
import type { Response } from '@chubbyts/chubbyts-undici-server/dist/server';
// if request original content-type was multipart/form-data, the current content-type and body is now application/x-www-form-urlencoded
const handler: Handler = async (request: ServerRequest): Promise
const multipartMiddleware = createMultipartMiddleware();
const response = await multipartMiddleware(new ServerRequest(), handler);
`
#### Input
`
----------------------------394107496171408467161617
Content-Disposition: form-data; name="id"
123e4567-e89b-12d3-a456-426655440000
----------------------------394107496171408467161617
Content-Disposition: form-data; name="name"
John Doe
----------------------------394107496171408467161617
Content-Disposition: form-data; name="address"
Content-Type: application/json
{
"street": "3, Garden St",
"city": "Hillsbery, UT"
}
----------------------------394107496171408467161617
Content-Disposition: form-data; name="red"; filename="red.png"
Content-Type: image/png
----------------------------394107496171408467161617
Content-Disposition: form-data; name="green"; filename="green.png"
Content-Type: image/png
----------------------------394107496171408467161617
Content-Disposition: form-data; name="blue"; filename="blue.png"
Content-Type: image/png
----------------------------394107496171408467161617--
`
#### Output
Optimized for human readability
```
id=123e4567-e89b-12d3-a456-426655440000&
name=John Doe&
address={\r\n "street": "3, Garden St",\r\n "city": "Hillsbery, UT"\r\n}&
red=/tmp/multipart/.../...; filename=red.png; mimeType=image/png&
green=/tmp/multipart/.../...; filename=green.png; mimeType=image/png&
blue=/tmp/multipart/.../...; filename=blue.png; mimeType=image/png&
2025 Dominik Zogg
[1]: https://www.npmjs.com/package/@chubbyts/chubbyts-undici-multipart
[2]: https://www.npmjs.com/package/@chubbyts/chubbyts-undici-server
[3]: https://www.npmjs.com/package/busboy