4.1.0 • Published 1 year ago

@marblejs/middleware-multipart v4.1.0

Weekly downloads
183
License
MIT
Repository
github
Last release
1 year ago

@marblejs/middleware-multipart

A multipart/form-data middleware for Marble.js based on busboy library.

Installation

$ npm i @marblejs/middleware-multipart

Requires @marblejs/core and @marblejs/http to be installed.

Documentation

For the latest updates, documentation, change log, and release information visit docs.marblejs.com and follow @marble_js on Twitter.

Usage


WARNING: Make sure that you always handle the files that a user uploads. Never add it as a global middleware since a malicious user could upload files to a route that you didn't anticipate. Only use this it on routes where you are handling the uploaded files.


By default middleware parses all incoming files and stores them in-memory.

Keep in mind that the middleware will parse only POST and PATCH request with multipart content-type.

import { multipart$ } from '@marblejs/middleware-multipart';

const effect$ = r.pipe(
  r.matchPath('/'),
  r.matchType('POST'),
  r.useEffect(req$ => req$.pipe(
    multipart$(),
    map(req => ({ body: {
      files: req.files['image_1'],  // file information
      body: req.body,             // all incoming body fields
    }}))
  )));

You can intercept incoming files and stream them to the different place, eg. to OS filesystem:

import { multipart$, StreamHandler } from '@marblejs/middleware-multipart';

const stream: StreamHandler = ({ file, fieldname }) => {
  const destination = // ...
  return of({ destination });
};

const effect$ = r.pipe(
  r.matchPath('/'),
  r.matchType('POST'),
  r.useEffect(req$ => req$.pipe(
    multipart$({
      stream,
      maxFileCount: 1,
      files: ['image_1'],
    }),
    map(req => ({ body: {
      files: req.files['image_1'],  // file information
      body: req.body,             // all incoming body fields
    }}))
  )));

Each file contains the following information:

keydescription
fieldnameField name specified in the form
filenameName of the file on the user's computer
encodingEncoding type of the file
mimetypeMime type of the file
sizeSize of the file in bytes
destinationThe place in which the file has been saved (if not in-memory)
bufferA Buffer of the entire file

You can define the following middleware options:

keydescription
maxFileCountThe total count of files that can be sent
maxFieldCountThe total count of fields that can be sent
maxFileSizeThe max possible file size in bytes
filesAn array of acceptable field names
streamA handler which you can use to stream incoming files to different location

License: MIT

4.1.0

1 year ago

4.0.3

2 years ago

4.0.2

2 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.5.2

3 years ago

4.0.0-rc.3

3 years ago

4.0.0-rc.2

3 years ago

4.0.0-next.32

3 years ago

4.0.0-rc.1

3 years ago

4.0.0-rc.0

3 years ago

4.0.0-next.26

3 years ago

4.0.0-next.27

3 years ago

4.0.0-next.28

3 years ago

4.0.0-next.25

3 years ago

4.0.0-next.22

3 years ago

4.0.0-next.20

3 years ago

4.0.0-next.21

3 years ago

4.0.0-next.19

3 years ago

3.5.1

3 years ago

4.0.0-next.16

3 years ago

4.0.0-next.17

3 years ago

4.0.0-next.15

3 years ago

4.0.0-next.14

3 years ago

4.0.0-next.13

3 years ago

4.0.0-next.11

3 years ago

4.0.0-next.9

3 years ago

4.0.0-next.8

3 years ago

4.0.0-next.0

3 years ago

4.0.0-next.2

3 years ago

3.5.0

3 years ago

3.4.9

3 years ago

3.4.8

3 years ago

3.4.7

3 years ago

3.4.6

3 years ago

3.4.5

3 years ago

3.4.4

3 years ago

3.4.3

4 years ago

3.4.2

4 years ago

3.4.2-dev.5

4 years ago

3.4.2-dev.6

4 years ago

3.4.2-dev.3

4 years ago

3.4.1

4 years ago

3.4.0

4 years ago

3.4.0-dev.8

4 years ago

3.4.0-dev.6

4 years ago

3.4.0-dev.5

4 years ago

3.3.0

4 years ago

3.3.0-dev.26

4 years ago

3.3.0-dev.25

4 years ago

3.3.0-dev.24

4 years ago

3.3.0-dev.23

4 years ago

3.3.0-dev.18

4 years ago

3.3.0-dev.19

4 years ago

3.3.0-dev.17

4 years ago

3.3.0-dev.16

4 years ago

3.3.0-dev.14

4 years ago

3.3.0-dev.13

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.2

4 years ago

3.1.1

4 years ago

3.1.0

4 years ago

3.0.2

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

3.0.0-rc.5

4 years ago

3.0.0-rc.4

4 years ago

3.0.0-rc.3

4 years ago

3.0.0-rc.2

4 years ago

3.0.0-rc.1

4 years ago

3.0.0-rc.0

4 years ago

3.0.0-next.106

4 years ago

3.0.0-next.105

4 years ago

3.0.0-next.101

4 years ago

3.0.0-next.98

4 years ago

3.0.0-next.97

4 years ago

3.0.0-next.94

4 years ago

3.0.0-next.96

4 years ago

3.0.0-next.92

4 years ago

3.0.0-next.91

4 years ago

3.0.0-next.90

4 years ago

3.0.0-next.89

4 years ago

3.0.0-next.88

4 years ago

3.0.0-next.87

4 years ago

3.0.0-next.84

4 years ago

3.0.0-next.83

4 years ago

3.0.0-next.82

4 years ago

3.0.0-next.81

4 years ago

3.0.0-next.80

4 years ago

3.0.0-next.77

4 years ago

3.0.0-next.78

4 years ago

3.0.0-next.76

4 years ago

3.0.0-next.75

5 years ago

3.0.0-next.74

5 years ago

3.0.0-next.73

5 years ago

3.0.0-next.72

5 years ago

3.0.0-next.71

5 years ago

3.0.0-next.70

5 years ago

3.0.0-next.69

5 years ago

3.0.0-next.68

5 years ago

3.0.0-next.66

5 years ago

3.0.0-next.64

5 years ago

3.0.0-next.63

5 years ago

2.4.0-dev.51

5 years ago

2.4.0-dev.48

5 years ago

2.4.0-dev.45

5 years ago

2.4.0-dev.44

5 years ago

2.4.0-dev.42

5 years ago

2.4.0-dev.37

5 years ago

2.4.0-dev.36

5 years ago

2.4.0-dev.35

5 years ago

2.3.0-dev.23

5 years ago

2.3.0-dev.22

5 years ago

2.3.0-dev.21

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago