Multipart/Form-Data And File Upload Middleware For Koa Written In ES6 And Optimised With JavaScript Compiler.
npm install @multipart/form-data
@multipart/form-data is Multipart/Form-Data And File Upload Middleware For Koa Written In ES6 And Optimised With JavaScript Compiler.
Originally, this was a Multer fork, however it was rewritten specifically for Koa2, and the interfaces were updated to be async rather than callbacks. Differences:
- When the file size limit is reached, the next middleware is called, rather than waiting to drain the request stream. This can result in the client-side EPIPE (connection reset) errors when sending files larger than allowed. But ideally, _Node.JS_ applications should be run behind a proxy such as NginX to limit the upload size.
- Removes the unnecessary typeis dependency that includes the mime-type database, just checks the _Content-Type_ to start with multipart/form-data.
- Compiled with _Google Closure Compiler_ and has just 1 dependency (text-decoding) to decode non-utf8 fields (e.g., when a form submitted had the accept-charset attribute).
``sh`
yarn add @multipart/form-data
- Table Of Contents
- API
- class FormData
* FormData
* FormDataConfig
* single(fieldname)
* array(fieldname, maxCount)
* fields(Array<FormDataField>)
* FormDataField
* none()
* any()
- FormDataFile
- Copyright & License
The package is available by importing its default and named functions:
`js`
import FormData, {
diskStorage, memoryStorage, FormDataError,
} from '@multipart/form-data'
This class is used to create middleware according to the required file upload strategy.
__FormData__: An instance to create middleware.
| Name | Type & Description |
|---|---|
| constructor | new (options?: !FormDataConfig) => FormData |
Creates a new form-data instance. | |
| single | (name: string) => !_goa.Middleware |
Accept a single file. | |
| array | (name: string, maxFiles: string) => !_goa.Middleware |
Accept multiple files. | |
| fields | (fields: !Array< method.">FormDataField>) => !_goa.Middleware |
Accept files according to the configured fields. | |
| none | () => !_goa.Middleware |
Do not accept files, only fields. | |
| any | () => !_goa.Middleware |
Accept any fields and files. |
Creates a new instance according to the config. It is later used to access the middleware functions described below.
__FormDataConfig__: The configuration for the instance.
| Name | Type | Description | Default |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
| dest | string | The directory where to store the files using the DiskStorage. If not specified, files will be saved in the system's temp directory (os.tmpdir()). | - |false
| storage | FormDataStorageEngine | An _instance_ of a custom storage engine. | - |
| fileFilter | FormDataFileFilter | The file filter. | - |
| limits | _goa.BusBoyLimits | The limits of the uploaded data. | - |
| preservePath | boolean | Whether to keep the full path of files instead of just the base name. | |
| |
` const app = new Goa() | ` |
| |
` const app = new Goa() | ` |
| |
` const app = new Goa() | ` |
| |
` const app = new Goa() | ` |
| |
` const app = new Goa() | ` |
_MultipartFormData_ adds a body object and a file or files object to the request object. The body hashmap contains the values of the text fields of the form, the file or files object contains the files uploaded via the form.
import('stream').Readable __stream.Readable__: A stream that pushes data when it becomes available.
__FormDataFile__: The information about each file.
| Name | Type | Description |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------- |
| __fieldname*__ | string | The field name specified in the form. |
| __originalname*__ | string | The name of the file on the user's computer. |
| __encoding*__ | string | The encoding type of the file. |
| __mimetype*__ | string | The mime type of the file. |
| __size*__ | number | The size of the file in bytes. |
| __destination*__ | string | The folder to which the file has been saved. Set by _DiskStorage_. |
| __filename*__ | string | The name of the file within the destination. Set by _DiskStorage_. |Buffer` of the entire file. Set by _MemoryStorage_. |
| __path*__ | string | The full path to the uploaded file. Set by _DiskStorage_. |
| __buffer*__ | Buffer | The
| __stream*__ | stream.Readable | The _Readable_ stream with the file data. This stream should not be read other than by a storage engine. |
GNU Affero General Public License v3.0
Original work by Multer's contributors under MIT license found in COPYING.
alt="Art Deco"> | © Art Deco for Idio 2019 | alt="Tech Nation Visa"> | Tech Nation Visa Sucks |
|---|