@chubbyts/chubbyts-http-multipart

1.1.0 • Public • Published

chubbyts-http-multipart

CI Coverage Status Mutation testing badge npm-version

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

Description

Chubbyts Http multipart request handling.

Requirements

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

Package Sidebar

Install

npm i @chubbyts/chubbyts-http-multipart

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

12.6 kB

Total Files

6

Last publish

Collaborators

  • dominikzogg