Gathering detailed insights and metrics for @multipart/form-data
Gathering detailed insights and metrics for @multipart/form-data
Gathering detailed insights and metrics for @multipart/form-data
Gathering detailed insights and metrics for @multipart/form-data
form-data
A library to create readable "multipart/form-data" streams. Can be used to submit forms and file uploads to other web applications.
form-data-encoder
Encode FormData content into the multipart/form-data format
formstream
A multipart/form-data encoded stream, helper for file upload.
multer
Middleware for handling `multipart/form-data`.
Multipart/Form-Data And File Upload Middleware For Koa Written In ES6 And Optimised With JavaScript Compiler.
npm install @multipart/form-data
Typescript
Module System
75
Supply Chain
99
Quality
74.9
Maintenance
100
Vulnerability
81.3
License
JavaScript (100%)
Total Downloads
65,161
Last Day
4
Last Week
205
Last Month
1,043
Last Year
13,802
AGPL-3.0 License
1 Stars
52 Commits
1 Branches
Updated on Dec 28, 2019
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
@multipart/form-data@1.0.1
Unpacked Size
268.76 kB
Size
75.97 kB
File Count
30
Cumulative downloads
Total Downloads
Last Day
0%
4
Compared to previous day
Last Week
-2.8%
205
Compared to previous week
Last Month
-9.1%
1,043
Compared to previous month
Last Year
-43.2%
13,802
Compared to previous year
@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:
typeis
dependency that includes the mime-type
database, just checks the Content-Type to start with multipart/form-data
.text-decoding
) to decode non-utf8 fields (e.g., when a form submitted had the accept-charset
attribute).1yarn add @multipart/form-data
The package is available by importing its default and named functions:
1import FormData, { 2 diskStorage, memoryStorage, FormDataError, 3} from '@multipart/form-data'
class FormData
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<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() ). | - |
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. | false |
| ||||||||||
|
| |||||||||
| ||||||||||
|
| |||||||||
|
Name | Type | Description |
---|---|---|
name* | string | The name of the field. |
maxCount | number | The maximum count of the field. |
1import Multipart from '@multipart/form-data' 2import Goa from '@goa/koa' 3 4const app = new Goa() 5const multipart = new Multipart({ 6 dest: 'temp', 7}) 8const middleware = multipart.fields([ 9 { name: 'file', maxCount: 2 }, 10 { name: 'picture', maxCount: 1 }, 11]) 12app.use(middleware) 13app.use((ctx) => { 14 log('Fields', ctx.req.body) 15 log('Files', ctx.req.files) 16})
1Fields: { hello: 'world', name: 'multipart' } 2Files: { file: 3 [ { fieldname: 'file', 4 originalname: 'test.txt', 5 encoding: '7bit', 6 mimetype: 'application/octet-stream', 7 destination: 'temp', 8 filename: '13093f0764', 9 path: 'temp/13093f0764', 10 size: 12 }, 11 { fieldname: 'file', 12 originalname: 'test.txt', 13 encoding: '7bit', 14 mimetype: 'application/octet-stream', 15 destination: 'temp', 16 filename: '22e2e6e6f7', 17 path: 'temp/22e2e6e6f7', 18 size: 12 } ], 19 picture: 20 [ { fieldname: 'picture', 21 originalname: 'large.jpg', 22 encoding: '7bit', 23 mimetype: 'application/octet-stream', 24 destination: 'temp', 25 filename: '352a1aea6a', 26 path: 'temp/352a1aea6a', 27 size: 1592548 } ] }
none()
: Do not accept files, only fields.1import Multipart from '@multipart/form-data' 2import Goa from '@goa/koa' 3 4const app = new Goa() 5const multipart = new Multipart({ 6 dest: 'temp', 7}) 8const middleware = multipart.none() 9app.use(middleware) 10app.use((ctx) => { 11 log('Fields', ctx.req.body) 12 log('Files', ctx.req.files) 13})
1Fields: { hello: 'world', name: 'multipart' } 2Files: undefined
any()
: Accept all files and fields.1import Multipart from '@multipart/form-data' 2import Goa from '@goa/koa' 3 4const app = new Goa() 5const multipart = new Multipart({ 6 dest: 'temp', 7}) 8const middleware = multipart.any() 9app.use(middleware) 10app.use((ctx) => { 11 log('Fields', ctx.req.body) 12 log('Files', ctx.req.files) 13})
1Fields: { hello: 'world', name: 'multipart' } 2Files: [ { fieldname: 'file', 3 originalname: 'test.txt', 4 encoding: '7bit', 5 mimetype: 'application/octet-stream', 6 destination: 'temp', 7 filename: '7218bd891a', 8 path: 'temp/7218bd891a', 9 size: 12 }, 10 { fieldname: 'picture', 11 originalname: 'large.jpg', 12 encoding: '7bit', 13 mimetype: 'application/octet-stream', 14 destination: 'temp', 15 filename: 'e7a8050980', 16 path: 'temp/e7a8050980', 17 size: 1592548 } ]
FormDataFile
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. |
path* | string | The full path to the uploaded file. Set by DiskStorage. |
buffer* | Buffer | The Buffer of the entire file. Set by MemoryStorage. |
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.
![]() | © Art Deco for Idio 2019 |
|
![]() | Tech Nation Visa Sucks |
---|
No vulnerabilities found.
No security vulnerabilities found.