Gathering detailed insights and metrics for multi-part-lite
Gathering detailed insights and metrics for multi-part-lite
Gathering detailed insights and metrics for multi-part-lite
Gathering detailed insights and metrics for multi-part-lite
npm install multi-part-lite
Typescript
Module System
Min. Node Version
Node Version
NPM Version
94.4
Supply Chain
99.5
Quality
75
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
3,259,970
Last Day
3,089
Last Week
14,309
Last Month
66,682
Last Year
931,715
6 Stars
6 Commits
1 Forks
2 Watching
13 Branches
1 Contributors
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
Last day
5.3%
3,089
Compared to previous day
Last week
-11.4%
14,309
Compared to previous week
Last month
2.1%
66,682
Compared to previous month
Last year
-1.9%
931,715
Compared to previous year
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
.
1$ npm install multi-part-lite --save
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})()
Constructor.
Object
with options:
multipart
data. Ex: if equal CustomBoundary
, boundary will be equal exactly CustomBoundary
.multipart
data. Ex: if equal CustomBoundary
, boundary will be equal something like --CustomBoundary567689371204
.Object
with defaults values:
filename
is not specified in the options of .append
method. By default file
.filename
is not specified in the options of .append
method. By default bin
.contentType
is not specified in the options of .append
method. By default application/octet-stream
.Adds a new data to the multipart/form-data
stream.
photo
.String
, Number
, Array
, Buffer
, ReadableStream
or even Vynil.file.bin
will be set. Ex: anonim.jpg
.application/octet-stream
will be set. Ex: image/jpeg
.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.
Returns a multipart/form-data
stream.
Returns a Promise
with a buffer of the multipart/form-data
stream data.
Returns the form boundary used in the multipart/form-data
stream.
1form.getBoundary(); // -> '--MultipartBoundary352840693617'
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
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
.
false
- headers will include content-length
header, otherwise there will be transfer-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//}
The MIT License (MIT)
Copyright (c) 2019 Alexey Bystrov
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
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
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
33 existing vulnerabilities detected
Details
Score
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 More