Skip to content

chubbyts/chubbyts-http-multipart

Folders and files

NameName
Last commit message
Last commit date

Latest commit

535d8a6 · Mar 4, 2025

History

15 Commits
Mar 4, 2025
Jun 18, 2024
Jun 24, 2024
Feb 17, 2024
Jan 3, 2025
Feb 4, 2025
Jan 3, 2025
Jan 3, 2025
Mar 4, 2025
Feb 17, 2024
Jun 18, 2024
Jan 3, 2025
Jan 3, 2025
Jun 18, 2024

Repository files navigation

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.3.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

2025 Dominik Zogg

About

Chubbyts Http multipart request handling

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2