Gathering detailed insights and metrics for async-busboy
Gathering detailed insights and metrics for async-busboy
Gathering detailed insights and metrics for async-busboy
Gathering detailed insights and metrics for async-busboy
npm install async-busboy
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
2,051,385
Last Day
412
Last Week
2,311
Last Month
12,171
Last Year
157,736
MIT License
167 Stars
103 Commits
58 Forks
7 Watchers
4 Branches
13 Contributors
Updated on Apr 23, 2024
Latest Version
1.1.0
Package Id
async-busboy@1.1.0
Size
6.40 kB
NPM Version
6.14.12
Node Version
14.16.1
Published on
May 25, 2021
Cumulative downloads
Total Downloads
Last Day
16.1%
412
Compared to previous day
Last Week
-14.6%
2,311
Compared to previous week
Last Month
1%
12,171
Compared to previous month
Last Year
-14%
157,736
Compared to previous year
1
4
The typical use case for this library is when handling forms that contain file upload field(s) mixed with other inputs. Parsing logic relies on busboy. Designed for use with Koa2 and Async/Await.
1import asyncBusboy from 'async-busboy'; 2 3// Koa 2 middleware 4async function(ctx, next) { 5 const {files, fields} = await asyncBusboy(ctx.req); 6 7 // Make some validation on the fields before upload to S3 8 if ( checkFiles(fields) ) { 9 files.map(uploadFilesToS3) 10 } else { 11 return 'error'; 12 } 13}
1import asyncBusboy from 'async-busboy';
2
3// Koa 2 middleware
4async function(ctx, next) {
5 const { fields } = await asyncBusboy(ctx.req, {
6 onFile: function(fieldname, file, filename, encoding, mimetype) {
7 uploadFilesToS3(file);
8 }
9 });
10
11 // Do validation, but files are already uploading...
12 if ( !checkFiles(fields) ) {
13 return 'error';
14 }
15}
1var asyncBusboy = require('async-busboy'); 2 3function(someHTTPRequest) { 4 asyncBusboy(someHTTPRequest).then(function(formData) { 5 // do something with formData.files 6 // do someting with formData.fields 7 }); 8}
The request streams are first written to temporary files using os.tmpdir()
. File read streams associated with the temporary files are returned from the call to async-busboy. When the consumer has drained the file read streams, the files will be automatically removed, otherwise the host OS should take care of the cleaning process.
If a custom onFile handler is specified in the options to async-busboy it
will only resolve an object containing fields, but instead no temporary files
needs to be created since the file stream is directly passed to the application.
Note that all file streams need to be consumed for async-busboy to resolve due
to the implementation of busboy. If you don't care about a received
file stream, simply call stream.resume()
to discard the content.
Make sure to serialize objects before sending them as formData. i.e:
1// Given an object that represent the form data: 2{ 3 'field1': 'value', 4 'objectField': { 5 'key': 'anotherValue' 6 }, 7 'arrayField': ['a', 'b'] 8 //... 9};
Should be sent as:
// -> field1[value]
// -> objectField[key][anotherKey]
// -> arrayField[0]['a']
// -> arrayField[1]['b']
// .....
Here is a function that can take care of this process
1const serializeFormData = (obj, formDataObj, namespace = null) => { 2 var formDataObj = formDataObj || {}; 3 var formKey; 4 for(var property in obj) { 5 if(obj.hasOwnProperty(property)) { 6 if(namespace) { 7 formKey = namespace + '[' + property + ']'; 8 } else { 9 formKey = property; 10 } 11 12 var value = obj[property]; 13 if(typeof value === 'object' && !(value instanceof File) && !(value instanceof Date)) { 14 serializeFormData(value, formDataObj, formKey); 15 } else if(value instanceof Date) { 16 formDataObj[formKey] = value.toISOString(); 17 } else { 18 formDataObj[formKey] = value; 19 } 20 } 21 } 22 return formDataObj; 23}; 24 25// -->
If you want to run some test locally, clone this repo, then run: node examples/index.js
From there you can use something like Postman to send POST
request to localhost:8080
.
Note: When using Postman make sure to not send a Content-Type
header, if it's filed by default, just delete it. (This is to let the boudary
header be generated automaticaly)
Form sending only octet-stream (files)
Form sending file octet-stream (files) and input fields. a. File and fields are processed has they arrive. Their order do not matter. b. Fields must be processed (for example validated) before processing the files.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 6/11 approved changesets -- score normalized to 5
Reason
7 existing vulnerabilities detected
Details
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
Score
Last Scanned on 2025-04-28
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