multipart/form-data encoded stream, helper for file upload.
Installations
npm install formstream
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
18.20.3
NPM Version
10.7.0
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (95.35%)
TypeScript (4.65%)
Developer
node-modules
Download Statistics
Total Downloads
43,449,272
Last Day
27,438
Last Week
143,806
Last Month
733,014
Last Year
10,096,378
GitHub Statistics
145 Stars
57 Commits
19 Forks
17 Watching
1 Branches
25 Contributors
Bundle Size
43.76 kB
Minified
12.88 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.5.1
Package Id
formstream@1.5.1
Unpacked Size
21.61 kB
Size
6.41 kB
File Count
5
NPM Version
10.7.0
Node Version
18.20.3
Publised On
07 Jun 2024
Total Downloads
Cumulative downloads
Total Downloads
43,449,272
Last day
-14.9%
27,438
Compared to previous day
Last week
-21.1%
143,806
Compared to previous week
Last month
-2.1%
733,014
Compared to previous month
Last year
-32.4%
10,096,378
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
formstream
A multipart/form-data encoded stream, helper for file upload.
Install
1npm install formstream
Quick Start
1var formstream = require('formstream'); 2var http = require('http'); 3 4var form = formstream(); 5 6// form.file('file', filepath, filename); 7form.file('file', './logo.png', 'upload-logo.png'); 8 9// other form fields 10form.field('foo', 'fengmk2').field('love', 'aerdeng'); 11 12// even send file content buffer directly 13// form.buffer(name, buffer, filename, mimeType) 14form.buffer('file2', new Buffer('This is file2 content.'), 'foo.txt'); 15 16var options = { 17 method: 'POST', 18 host: 'upload.cnodejs.net', 19 path: '/store', 20 headers: form.headers() 21}; 22var req = http.request(options, function (res) { 23 console.log('Status: %s', res.statusCode); 24 res.on('data', function (data) { 25 console.log(data.toString()); 26 }); 27}); 28 29form.pipe(req);
Chaining
1var fs = require('fs'); 2var formstream = require('formstream'); 3 4var filepath = './logo.png'; 5fs.stat(filepath, function (err, stat) { 6 formstream() 7 .field('status', 'share picture') 8 .field('access_token', 'your access token') 9 .file('pic', filepath, 'logo.png', stat.size) 10 .pipe(process.stdout); // your request stream 11});
Set min chunk buffer size
Some web servers have a limit on the number of chunks, and you can set minChunkSize
to ensure the size of chunk sent to the server.
1var fs = require('fs'); 2var FormStream = require('formstream'); 3 4var filepath = './big-file.zip'; 5fs.stat(filepath, function (err, stat) { 6 new FormStream({ 7 // send >= 2MB chunk buffer size to the server 8 minChunkSize: 1024 * 1024 * 2, 9 }).field('status', 'share file') 10 .field('access_token', 'your access token') 11 .file('file', filepath, 'big-file.zip', stat.size) 12 .pipe(process.stdout); // your request stream 13});
API Doc
formstream([options])
Create a form instance.
Arguments
- options.minChunkSize Number - min chunk size to emit data event
Returns
Form - form instance
FormStream#field(name, value)
Add a normal field to the form.
Arguments
- name String - Name of field
- value String - Value of field
Returns
Form - form instance
FormStream#file(name, filepath[, filename][, filesize])
Add a local file to be uploaded to the form.
Arguments
- name String - Name of file field
- filepath String - Local path of the file to be uploaded
- filename String - Optional. Name of the file (will be the base name of
filepath
if empty) - filesize Number - Optional. Size of the file (will not generate
Content-Length
header if not specified)
Returns
Form - form instance
FormStream#buffer(name, buffer, filename[, contentType])
Add a buffer as a file to upload.
Arguments
- name String - Name of field
- buffer Buffer - The buffer to be uploaded
- filename String - The file name that tells the remote server
- contentType String - Optional. Content-Type (aka. MIME Type) of content (will be infered with
filename
if empty)
Returns
Form - form instance
FormStream#stream(name, stream, filename[, contentType][, size])
Add a readable stream as a file to upload. Event 'error' will be emitted if an error occured.
Arguments
- name String - Name of field
- stream stream.Readable - A readable stream to be piped
- filename String - The file name that tells the remote server
- contentType String - Optional. Content-Type (aka. MIME Type) of content (will be infered with
filename
if empty) - size Number - Optional. Size of the stream (will not generate
Content-Length
header if not specified)
Returns
Form - form instance
FormStream#headers([headers])
Get headers for the request.
Arguments
- headers Object - Additional headers
Example
1var headers = form.headers({ 2 'Authorization': 'Bearer kei2akc92jmznvnkeh09sknzdk', 3 'Accept': 'application/vnd.github.v3.full+json' 4});
Returns
Object - Headers to be sent.
Event 'error'
Emitted if there was an error receiving data.
Event 'data'
The 'data' event emits when a Buffer was used.
See Node.js Documentation for more.
Event 'end'
Emitted when the stream has received no more 'data' events will happen.
See Node.js Documentation for more.
License
Contributors
fengmk2 | xingrz | semantic-release-bot | fjc0k | mrspeiser | dead-horse |
---|---|---|---|---|---|
shaozj |
This project follows the git-contributor spec, auto updated at Wed May 15 2024 00:34:12 GMT+0800
.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
SAST tool is not run on all commits -- score normalized to 2
Details
- Warn: 3 commits out of 11 are checked with a SAST tool
Reason
Found 4/30 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/release.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
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
Score
4.3
/10
Last Scanned on 2025-01-27
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