@web3-storage/multipart-parser
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @web3-storage/multipart-parser

Weekly Downloads

413,822

Version

1.0.0

License

(Apache-2.0 AND MIT)

Unpacked Size

53.9 kB

Total Files

21

Last publish

Collaborators

  • it-dag-house
  • gozala
  • olizilla
  • vascosantos
  • alanshaw