@chubbyts/chubbyts-http-multipart
v1.1.0
Published
Chubbyts Http multipart request handling
Downloads
7
Maintainers
Readme
chubbyts-http-multipart
Description
Chubbyts Http multipart request handling.
Requirements
- node: 16
- @chubbyts/chubbyts-http-types: ^1.2.3
- busboy: ^1.6.0
Installation
Through NPM as @chubbyts/chubbyts-http-multipart.
npm i @chubbyts/chubbyts-http-multipart@^1.1.0
Usage
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);
Example
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
<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--
Output
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&
Copyright
2024 Dominik Zogg