@marblejs/middleware-multipart
A multipart/form-data middleware based on busboy library.
Installation
Requires @marblejs/core
to be installed.
Importing
Type declaration
Parameters
parameter | definition |
options | <optional> |
ParserOpts
parameter | definition |
files | <optional> |
stream | <optional> |
maxFileSize | <optional> |
maxFileCount | <optional> |
maxFieldSize | <optional> |
maxFieldCount | <optional> |
Usage
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 handle. Only use this it on routes where you are handling the uploaded files.
In-memory storage:
Out-of-memory storage:
You can intercept incoming files and stream them to the different place, eg. to OS filesystem or AWS S3 bucket. The prervious example shows how you can specify constraints for multipart/form-data parsing the accepts only one image_1
field.
Each file included inside req.files
object contains the following information:
key | description |
| Field name specified in the form |
| Name of the file on the user's computer |
| Encoding type of the file |
| Mime type of the file |
| Size of the file in bytes (in-memory parsing) |
| The place in which the file has been saved (if not in-memory parsing) |
| A |
You can define the following middleware options:
key | description |
| The total count of files that can be sent |
| The total count of fields that can be sent |
| The max possible file size in bytes |
| An array of acceptable field names |
| A handler which you can use to stream incoming files to different location |
Last updated