Chubbyts Http multipart request handling.
- node: 16
- @chubbyts/chubbyts-http-types: ^1.2.3
- busboy: ^1.6.0
Through NPM as @chubbyts/chubbyts-http-multipart.
npm i @chubbyts/chubbyts-http-multipart@^1.1.0
import { createMultipartMiddleware } from '@chubbyts/chubbyts-http-multipart/dist/multipart-middleware';
import type { Handler } from '@chubbyts/chubbyts-http-types/dist/handler';
import type { Response, ServerRequest } from '@chubbyts/chubbyts-http-types/dist/message';
const request: ServerRequest = ...;
const response: Response = ...;
// 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<Response> ...;
const multipartMiddleware = createMultipartMiddleware();
const response = await multipartMiddleware(request, handler);
----------------------------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
<binary>
----------------------------394107496171408467161617
Content-Disposition: form-data; name="green"; filename="green.png"
Content-Type: image/png
<binary>
----------------------------394107496171408467161617
Content-Disposition: form-data; name="blue"; filename="blue.png"
Content-Type: image/png
<binary>
----------------------------394107496171408467161617--
Optimized for human readability
id=123e4567-e89b-12d3-a456-426655440000&
name=John Doe&
address={\n "street": "3, Garden St",\n "city": "Hillsbery, UT"\n}&
red=/tmp/multipart/.../red.png; filename=red.png; mimeType=image/png&
green=/tmp/multipart/.../green.png; filename=green.png; mimeType=image/png&
blue=/tmp/multipart/.../blue.png; filename=blue.png; mimeType=image/png&
2024 Dominik Zogg