express-fileupload vs connect-busboy vs busboy vs form-data vs formidable vs koa-body vs multer
Node.js File Upload Libraries
express-fileuploadconnect-busboybusboyform-dataformidablekoa-bodymulterSimilar Packages:

Node.js File Upload Libraries

These libraries facilitate file uploads in Node.js applications, providing various methods to handle multipart/form-data. They differ in terms of middleware integration, performance, and feature sets, catering to different use cases and frameworks such as Express and Koa. Understanding their unique functionalities helps developers choose the right tool for their specific needs.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
express-fileupload496,4581,560119 kB24a year agoMIT
connect-busboy63,0761564.57 kB1--
busboy03,000124 kB38--
form-data02,35283.9 kB140a month agoMIT
formidable0-204 kB-a year agoMIT
koa-body095563.8 kB72 months agoMIT
multer012,06232.8 kB27725 days agoMIT

Feature Comparison: express-fileupload vs connect-busboy vs busboy vs form-data vs formidable vs koa-body vs multer

Integration

  • express-fileupload:

    Express-Fileupload is designed specifically for Express, providing a plug-and-play solution for file uploads with minimal configuration needed.

  • connect-busboy:

    Connect-Busboy integrates Busboy with Connect middleware, simplifying the process of handling file uploads in Connect-based applications.

  • busboy:

    Busboy is a low-level streaming parser that requires manual integration into your application, giving you full control over the file upload process but requiring more setup.

  • form-data:

    Form-Data is primarily used for constructing multipart/form-data requests, making it suitable for client-side applications rather than server-side file handling.

  • formidable:

    Formidable can be used with any Node.js application, providing a comprehensive solution for file uploads and form parsing, but it requires more setup than simpler libraries.

  • koa-body:

    Koa-Body integrates seamlessly with Koa, allowing for easy handling of multipart/form-data in Koa applications, with a straightforward API.

  • multer:

    Multer is a middleware for Express that simplifies file uploads, providing built-in support for various storage options and configuration.

Performance

  • express-fileupload:

    Express-Fileupload is easy to use but may not be as performant as Busboy for very large files, as it buffers the entire file in memory before processing.

  • connect-busboy:

    Performance is similar to Busboy, as it utilizes the same underlying library, but may introduce slight overhead due to middleware integration.

  • busboy:

    Busboy is highly efficient for large file uploads due to its streaming nature, which minimizes memory usage and allows for processing files in chunks.

  • form-data:

    Form-Data is optimized for creating requests but is not designed for handling uploads on the server side, so performance considerations depend on the use case.

  • formidable:

    Formidable is efficient for file uploads but can consume more memory than Busboy, especially with large files, as it buffers uploads before processing.

  • koa-body:

    Koa-Body is designed for Koa applications and offers good performance, but like Express-Fileupload, it may buffer files in memory depending on configuration.

  • multer:

    Multer provides excellent performance for file uploads in Express applications, with options to store files in memory or on disk, allowing for flexible handling.

Ease of Use

  • express-fileupload:

    Express-Fileupload is very easy to use, with minimal setup required, making it ideal for beginners or quick prototypes.

  • connect-busboy:

    Connect-Busboy is straightforward to use within Connect applications, providing a simple API for file uploads without much boilerplate code.

  • busboy:

    Busboy requires more manual setup and configuration, making it less beginner-friendly but offering greater control for experienced developers.

  • form-data:

    Form-Data is easy to use for constructing requests but is not focused on server-side file handling, which may require additional libraries for uploads.

  • formidable:

    Formidable has a moderate learning curve, offering comprehensive functionality but requiring more understanding of its API and options.

  • koa-body:

    Koa-Body is user-friendly for Koa applications, providing a clean API for handling file uploads and form data with minimal configuration.

  • multer:

    Multer is designed to be easy to use with Express, allowing developers to quickly set up file uploads with clear configuration options.

File Handling Features

  • express-fileupload:

    Express-Fileupload provides simple file handling features but lacks advanced options for file processing compared to other libraries.

  • connect-busboy:

    Connect-Busboy inherits Busboy's file handling capabilities, allowing for streaming uploads within Connect applications.

  • busboy:

    Busboy allows for streaming file uploads, enabling developers to process files as they are being uploaded, which is useful for large files.

  • form-data:

    Form-Data focuses on creating multipart requests and does not handle file uploads on the server side, requiring additional handling for uploads.

  • formidable:

    Formidable offers robust file handling features, including file renaming, size limits, and error handling, making it suitable for complex applications.

  • koa-body:

    Koa-Body supports file uploads and provides a clean API for accessing uploaded files, making it easy to work with in Koa applications.

  • multer:

    Multer provides extensive file handling features, including storage options, file size limits, and file filtering, making it highly configurable for various use cases.

Community and Support

  • express-fileupload:

    Express-Fileupload has a large user base and community support, making it easy to find help and resources online.

  • connect-busboy:

    Connect-Busboy benefits from the Connect community, which provides support and resources for users.

  • busboy:

    Busboy has a smaller community compared to some other libraries, but it is well-maintained and widely used in production applications.

  • form-data:

    Form-Data is widely used for constructing requests and has good community support, but it is not focused on server-side uploads.

  • formidable:

    Formidable has been around for a while and has a solid community, providing ample resources and support for developers.

  • koa-body:

    Koa-Body is part of the Koa ecosystem, which has a growing community and support for Koa-related libraries.

  • multer:

    Multer has a large community and is widely adopted in Express applications, ensuring good support and documentation.

How to Choose: express-fileupload vs connect-busboy vs busboy vs form-data vs formidable vs koa-body vs multer

  • express-fileupload:

    Use Express-Fileupload for an easy-to-use solution that integrates directly with Express. It simplifies file upload handling with minimal setup, making it suitable for quick projects or prototypes.

  • connect-busboy:

    Select Connect-Busboy if you are using Connect middleware and need a simple way to integrate Busboy with your existing Connect-based application. It offers a straightforward approach to handle file uploads seamlessly within Connect.

  • busboy:

    Choose Busboy for a lightweight, low-level streaming parser that is efficient for handling large file uploads without additional overhead. It is ideal for applications that require fine-grained control over file processing.

  • form-data:

    Opt for Form-Data when you need to construct and send multipart/form-data requests from Node.js. It is particularly useful for client-side applications that require file uploads to a server.

  • formidable:

    Choose Formidable for a robust file upload solution that supports file uploads and form parsing. It is well-suited for applications that require detailed file handling and form data processing.

  • koa-body:

    Select Koa-Body if you are building applications with Koa and need a middleware that supports multipart/form-data. It provides a clean API for handling file uploads and form data in Koa applications.

  • multer:

    Use Multer when working with Express and need a powerful middleware for handling multipart/form-data. It offers extensive configuration options for file storage and limits, making it ideal for complex file upload scenarios.

README for express-fileupload

express-fileupload

Simple express middleware for uploading files.

npm downloads per month CircleCI Coverage Status

Help us Improve express-fileupload

This package is still very much supported and maintained. But the more help the better. If you're interested any of the following:

  • Ticket and PR triage
  • Feature scoping and implementation
  • Maintenance (upgrading packages, fixing security vulnerabilities, etc)

...please contact richardgirges '-at-' gmail.com

Install

# With NPM
npm i express-fileupload

# With Yarn
yarn add express-fileupload

Usage

When you upload a file, the file will be accessible from req.files.

Example:

  • You're uploading a file called car.jpg
  • Your input's name field is foo: <input name="foo" type="file" />
  • In your express server request, you can access your uploaded file from req.files.foo:
app.post('/upload', function(req, res) {
  console.log(req.files.foo); // the uploaded file object
});

The req.files.foo object will contain the following:

  • req.files.foo.name: "car.jpg"
  • req.files.foo.mv: A function to move the file elsewhere on your server. Can take a callback or return a promise.
  • req.files.foo.mimetype: The mimetype of your file
  • req.files.foo.data: A buffer representation of your file, returns empty buffer in case useTempFiles option was set to true.
  • req.files.foo.tempFilePath: A path to the temporary file in case useTempFiles option was set to true.
  • req.files.foo.truncated: A boolean that represents if the file is over the size limit
  • req.files.foo.size: Uploaded size in bytes
  • req.files.foo.md5: MD5 checksum of the uploaded file

Notes about breaking changes with MD5 handling:

  • Before 1.0.0, md5 is an MD5 checksum of the uploaded file.
  • From 1.0.0 until 1.1.1, md5 is a function to compute an MD5 hash (Read about it here.).
  • From 1.1.1 until 1.5.1, md5 is reverted back to MD5 checksum value and also added full MD5 support in case you are using temporary files.
  • From 1.5.1 onward, md5 still holds the checksum value, but the checksum is generated with the provided hashAlgorithm option. The property name remains md5 for backwards compatibility.

Examples

Using Busboy Options

Pass in Busboy options directly to the express-fileupload middleware. Check out the Busboy documentation here.

app.use(fileUpload({
  limits: { fileSize: 50 * 1024 * 1024 },
}));

Using useTempFile Options

Use temp files instead of memory for managing the upload process.

// Note that this option available for versions 1.0.0 and newer. 
app.use(fileUpload({
    useTempFiles : true,
    tempFileDir : '/tmp/'
}));

Using debug option

You can set debug option to true to see some logging about upload process. In this case middleware uses console.log and adds Express-file-upload prefix for outputs. You can set a custom logger having .log() method to the logger option.

It will show you whether the request is invalid and also common events triggered during upload. That can be really useful for troubleshooting and we recommend attaching debug output to each issue on Github.

Output example:

Express-file-upload: Temporary file path is /node/express-fileupload/test/temp/tmp-16-1570084843942
Express-file-upload: New upload started testFile->car.png, bytes:0
Express-file-upload: Uploading testFile->car.png, bytes:21232...
Express-file-upload: Uploading testFile->car.png, bytes:86768...
Express-file-upload: Upload timeout testFile->car.png, bytes:86768
Express-file-upload: Cleaning up temporary file /node/express-fileupload/test/temp/tmp-16-1570084843942...

Description:

  • Temporary file path is... says that useTempfiles was set to true and also shows you temp file name and path.
  • New upload started testFile->car.png says that new upload started with field testFile and file name car.png.
  • Uploading testFile->car.png, bytes:21232... shows current progress for each new data chunk.
  • Upload timeout means that no data came during uploadTimeout.
  • Cleaning up temporary file Here finaly we see cleaning up of the temporary file because of upload timeout reached.

Available Options

Pass in non-Busboy options directly to the middleware. These are express-fileupload specific options.

OptionAcceptable ValuesDetails
createParentPath
  • false (default)
  • true
Automatically creates the directory path specified in .mv(filePathName)
uriDecodeFileNames
  • false (default)
  • true
Applies uri decoding to file names if set true.
safeFileNames
  • false (default)
  • true
  • regex
Strips characters from the upload's filename. You can use custom regex to determine what to strip. If set to true, non-alphanumeric characters except dashes and underscores will be stripped. This option is off by default.

Example #1 (strip slashes from file names): app.use(fileUpload({ safeFileNames: /\\/g }))
Example #2: app.use(fileUpload({ safeFileNames: true }))
preserveExtension
  • false (default)
  • true
  • Number
Preserves filename extension when using safeFileNames option. If set to true, will default to an extension length of 3. If set to Number, this will be the max allowable extension length. If an extension is smaller than the extension length, it remains untouched. If the extension is longer, it is shifted.

Example #1 (true):
app.use(fileUpload({ safeFileNames: true, preserveExtension: true }));
myFileName.ext --> myFileName.ext

Example #2 (max extension length 2, extension shifted):
app.use(fileUpload({ safeFileNames: true, preserveExtension: 2 }));
myFileName.ext --> myFileNamee.xt
abortOnLimit
  • false (default)
  • true
Returns a HTTP 413 when the file is bigger than the size limit if true. Otherwise, it will add a truncated = true to the resulting file structure.
responseOnLimit
  • 'File size limit has been reached' (default)
  • String
Response which will be send to client if file size limit exceeded when abortOnLimit set to true.
limitHandler
  • false (default)
  • function(req, res, next)
User defined limit handler which will be invoked if the file is bigger than configured limits.
useTempFiles
  • false (default)
  • true
By default this module uploads files into RAM. Setting this option to True turns on using temporary files instead of utilising RAM. This avoids memory overflow issues when uploading large files or in case of uploading lots of files at same time.
tempFileDir
  • String (path)
Path to store temporary files.
Used along with the useTempFiles option. By default this module uses 'tmp' folder in the current working directory.
You can use trailing slash, but it is not necessary.
tempFilePermissions
  • 644 (default)
  • Integer
Permissions applied to temporary files.
Used along with the useTempFiles option. By default this module uses '644' permissions.
You should use this option if using shared hosting - to protect user data from being accessed by other users on the server.
parseNested
  • false (default)
  • true
By default, req.body and req.files are flattened like this: {'name': 'John', 'hobbies[0]': 'Cinema', 'hobbies[1]': 'Bike'}

When this option is enabled they are parsed in order to be nested like this: {'name': 'John', 'hobbies': ['Cinema', 'Bike']}
debug
  • false (default)
  • true
Turn on/off upload process logging. Can be useful for troubleshooting.
logger
  • console (default)
  • {log: function(msg: string)}
Customizable logger to write debug messages to. Console is default.
uploadTimeout
  • 60000 (default)
  • Integer
This defines how long to wait for data before aborting. Set to 0 if you want to turn off timeout checks.
hashAlgorithm
  • md5 (default)
  • String
Allows the usage of alternative hashing algorithms for file integrity checks. This option must be an algorithm that is supported on the running system's installed OpenSSL version. On recent releases of OpenSSL, openssl list -digest-algorithms will display the available digest algorithms.

Help Wanted

Looking for additional maintainers. Please contact richardgirges [ at ] gmail.com if you're interested. Pull Requests are welcome!

Thanks & Credit

Brian White for his stellar work on the Busboy Package and the connect-busboy Package