Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

A simple multipart/form-data parser to use with ReadableStreams

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENCE-APACHE
MIT
LICENCE-MIT
Notifications You must be signed in to change notification settings

web3-storage/multipart-parser

Repository files navigation

multipart-parser

A simple multipart/form-data parser to use with ReadableStreams

Based on https://github.com/ssttevee/js-multipart-parser

Install

# install it as a dependency
$ npm i @web3-storage/multipart-parser

Usage

import { parseMultipart } from '@web3-storage/multipart-parser';

...

async function requestHandler(req) {
    const boundary = '----whatever';
    const parts = await parseMultipart(req.body, boundary);
    const fd = new FormData();
    for (const { name, data, filename, contentType } of parts) {
        if (filename) {
            fd.append(name, new Blob([data], { type: contentType }), filename);
        } else {
            fd.append(name, new TextDecoder().decode(data), filename);
        }
    }
}

Releasing

You can publish by either running npm publish in the dist directory or using npx ipjs publish.

About

A simple multipart/form-data parser to use with ReadableStreams

Resources

License

Unknown, MIT licenses found

Licenses found

Unknown
LICENCE-APACHE
MIT
LICENCE-MIT

Stars

Watchers

Forks

Packages