Installations
npm install multi-part-lite
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=8.3.0
Node Version
10.10.0
NPM Version
6.5.0
Score
96.1
Supply Chain
99.5
Quality
75
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
strikeentco
Download Statistics
Total Downloads
3,253,050
Last Day
815
Last Week
13,745
Last Month
63,195
Last Year
930,522
GitHub Statistics
6 Stars
6 Commits
1 Forks
2 Watching
13 Branches
1 Contributors
Bundle Size
5.02 kB
Minified
2.00 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.0.0
Package Id
multi-part-lite@1.0.0
Size
6.13 kB
NPM Version
6.5.0
Node Version
10.10.0
Publised On
11 Aug 2019
Total Downloads
Cumulative downloads
Total Downloads
3,253,050
Last day
-18.7%
815
Compared to previous day
Last week
-28%
13,745
Compared to previous week
Last month
-11.8%
63,195
Compared to previous month
Last year
-2%
930,522
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
multi-part-lite
A multi-part-lite
allows you to create multipart/form-data Stream
and Buffer
, which can be used to submit forms and file uploads to other web applications.
There are no external dependencies, so it as fast and simple as possible.
Supports: Strings
, Numbers
, Arrays
, Streams
, Buffers
and Vinyl
.
Install
1$ npm install multi-part-lite --save
Usage
Usage with got
as Stream
:
1const got = require('got'); 2const Multipart = require('multi-part-lite'); 3const form = new Multipart(); 4 5form.append('photo', got.stream('https://avatars1.githubusercontent.com/u/2401029'), { filename: 'image.jpg', contentType: 'image/jpeg' }); 6form.append('field', 'multi-part test'); 7 8got.post('127.0.0.1:3000', { headers: form.getHeaders(), body: form.stream() });
Usage with got
as Buffer
:
1const got = require('got'); 2const Multipart = require('multi-part-lite'); 3const form = new Multipart(); 4 5form.append('photo', got.stream('https://avatars1.githubusercontent.com/u/2401029'), { filename: 'image.jpg', contentType: 'image/jpeg' }); 6form.append('field', 'multi-part test'); 7 8(async () => { 9 const body = await form.buffer(); 10 got.post('127.0.0.1:3000', { headers: form.getHeaders(false), body }); 11})()
Usage with http
/https
as Stream
:
1const http = require('http'); 2const https = require('https'); 3const Multipart = require('multi-part-lite'); 4const form = new Multipart(); 5 6form.append('photo', https.request('https://avatars1.githubusercontent.com/u/2401029'), { filename: 'image.jpg', contentType: 'image/jpeg' }); 7 8form.stream().pipe(http.request({ headers: form.getHeaders(), hostname: '127.0.0.1', port: 3000, method: 'POST' }));
Usage with http
/https
as Buffer
:
1const http = require('http'); 2const https = require('https'); 3const Multipart = require('multi-part-lite'); 4const form = new Multipart(); 5 6form.append('photo', https.request('https://avatars1.githubusercontent.com/u/2401029'), { filename: 'image.jpg', contentType: 'image/jpeg' }); 7 8(async () => { 9 const body = await form.buffer(); 10 const req = http.request({ headers: form.getHeaders(false), hostname: '127.0.0.1', port: 3000, method: 'POST' }); 11 req.end(body); 12})()
API
new Multipart([options])
Constructor.
Params:
- [options] (Object) -
Object
with options:- [boundary] (String|Number) - Custom boundary for
multipart
data. Ex: if equalCustomBoundary
, boundary will be equal exactlyCustomBoundary
. - [boundaryPrefix] (String|Number) - Custom boundary prefix for
multipart
data. Ex: if equalCustomBoundary
, boundary will be equal something like--CustomBoundary567689371204
. - [defaults] (Object) -
Object
with defaults values:- [name] (String) - File name which will be used, if
filename
is not specified in the options of.append
method. By defaultfile
. - [ext] (String) - File extension which will be used, if
filename
is not specified in the options of.append
method. By defaultbin
. - [type] (String) - File content-type which will be used, if
contentType
is not specified in the options of.append
method. By defaultapplication/octet-stream
.
- [name] (String) - File name which will be used, if
- [boundary] (String|Number) - Custom boundary for
.append(name, value, [options])
Adds a new data to the multipart/form-data
stream.
Params:
- name (String|Number) - Field name. Ex:
photo
. - value (Mixed) - Value can be
String
,Number
,Array
,Buffer
,ReadableStream
or even Vynil. - [options] (Object) - Additional options:
- filename (String) - File name. You should always specify file name with extension, otherwise
file.bin
will be set. Ex:anonim.jpg
. - contentType (String) - File content type. You should always specify content-type, otherwise
application/octet-stream
will be set. Ex:image/jpeg
.
- filename (String) - File name. You should always specify file name with extension, otherwise
If value
is an array, append
will be called for each value:
1form.append('array', [0, [2, 3], 1]); 2 3// similar to 4 5form.append('array', 0); 6form.append('array', 2); 7form.append('array', 3); 8form.append('array', 1);
Null
, false
and true
will be converted to '0'
, '0'
and '1'
. Numbers will be converted to strings also.
Warning: You must specify the correct contentType
and filename
. This library doesn't validate them. You can use multi-part
library which can handle it for you.
.stream()
Returns a multipart/form-data
stream.
.buffer()
Returns a Promise
with a buffer of the multipart/form-data
stream data.
.getBoundary()
Returns the form boundary used in the multipart/form-data
stream.
1form.getBoundary(); // -> '--MultipartBoundary352840693617'
.getLength()
Returns the length of a buffer of the multipart/form-data
stream data.
Should be called after .buffer()
;
For .stream()
it's always 0
.
1await form.buffer(); 2form.getLength(); // -> 12345
.getHeaders(chunked = true)
Returns the headers.
If you want to get correct content-length
, you should call it after .buffer()
. There is no way to know content-length
of the .stream()
, so it will be always 0
.
Params:
- chunked (Boolean) - If
false
- headers will includecontent-length
header, otherwise there will betransfer-encoding: 'chunked'
.
1form.getHeaders(); // -> 2//{ 3// 'transfer-encoding': 'chunked', 4// 'content-type': 'multipart/form-data; boundary="--MultipartBoundary352840693617"' 5//}
With .buffer()
:
1form.getHeaders(false); // -> 2//{ 3// 'content-length': '0', 4// 'content-type': 'multipart/form-data; boundary="--MultipartBoundary352840693617"' 5//} 6 7await form.buffer(); 8form.getHeaders(false); // -> 9//{ 10// 'content-length': '12345', 11// 'content-type': 'multipart/form-data; boundary="--MultipartBoundary352840693617"' 12//}
License
The MIT License (MIT)
Copyright (c) 2019 Alexey Bystrov
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/2 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 4 are checked with a SAST tool
Reason
33 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-6chw-6frg-f759
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-wm7h-9275-46v2
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-2j2x-2gpw-g8fm
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-px4h-xg32-q955
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/10
Last Scanned on 2025-01-20
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreGathering detailed insights and metrics for multi-part-lite