express-fileupload vs busboy vs form-data vs formidable vs multer
File Upload Middleware for Node.js
express-fileuploadbusboyform-dataformidablemulterSimilar Packages:

File Upload Middleware for Node.js

These npm packages are designed to handle file uploads in Node.js applications. They provide various functionalities for parsing incoming multipart/form-data requests, which is essential for handling file uploads from clients. Each package has its own strengths and weaknesses, making them suitable for different scenarios based on project requirements, performance needs, and ease of use. Understanding these differences is crucial for selecting the right package for your application.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
express-fileupload502,4741,561119 kB248 months agoMIT
busboy02,996124 kB37--
form-data02,35681.2 kB1373 months agoMIT
formidable0-204 kB-10 months agoMIT
multer012,00429.5 kB2477 months agoMIT

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

Ease of Use

  • express-fileupload:

    Express-fileupload is designed for simplicity and ease of use, making it ideal for developers who want to quickly implement file uploads without extensive configuration.

  • busboy:

    Busboy is a low-level streaming parser that requires more setup and understanding of streams. It may not be the best choice for beginners or those looking for a quick implementation.

  • form-data:

    Form-data is primarily used for sending files to external services rather than handling uploads, so it does not provide an easy interface for incoming file uploads.

  • formidable:

    Formidable offers a straightforward API for handling file uploads, but it may require a bit more configuration compared to express-fileupload.

  • multer:

    Multer is easy to set up and integrates seamlessly with Express.js, providing a user-friendly experience for handling file uploads.

Performance

  • express-fileupload:

    Express-fileupload is suitable for small to medium files, but may not perform as well as Busboy for larger uploads due to its in-memory processing.

  • busboy:

    Busboy is highly performant due to its streaming nature, allowing for efficient handling of large files without consuming excessive memory.

  • form-data:

    Form-data is not used for handling incoming uploads, so performance considerations are more relevant when sending files to external services.

  • formidable:

    Formidable performs well for moderate file sizes but can become slower with very large files due to its processing model.

  • multer:

    Multer is efficient for handling file uploads, especially when configured with disk storage, but may require optimization for very large files.

File Size Limitations

  • express-fileupload:

    Express-fileupload also supports file size limits, but it may not be as flexible as Busboy in terms of configuration.

  • busboy:

    Busboy allows you to set file size limits easily, making it suitable for applications that need to enforce strict upload limits.

  • form-data:

    Form-data does not impose file size limits as it is used for sending files, not receiving them.

  • formidable:

    Formidable allows you to set file size limits and provides feedback on upload progress, making it a good choice for applications that need to manage large uploads.

  • multer:

    Multer allows you to set file size limits and provides options for handling errors when limits are exceeded.

Streaming Support

  • express-fileupload:

    Express-fileupload does not support streaming; it buffers the entire file in memory before processing, which may lead to performance issues with large files.

  • busboy:

    Busboy excels in streaming file uploads, allowing files to be processed as they are received, which is ideal for large files.

  • form-data:

    Form-data is designed for constructing requests, not for streaming uploads, so it lacks this feature.

  • formidable:

    Formidable supports streaming uploads, allowing for efficient processing of files as they are received, similar to Busboy.

  • multer:

    Multer does not support streaming in the same way as Busboy, as it buffers files in memory or on disk before processing.

Integration with Express

  • express-fileupload:

    Express-fileupload is specifically designed for Express, making it the easiest to integrate with minimal configuration.

  • busboy:

    Busboy can be integrated with Express, but it requires more manual setup compared to other packages.

  • form-data:

    Form-data is not designed for Express integration, as it is used for sending requests rather than handling them.

  • formidable:

    Formidable can be integrated with Express, but it requires additional setup compared to express-fileupload.

  • multer:

    Multer is built for Express and provides a straightforward middleware approach, making it very easy to use in Express applications.

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

  • express-fileupload:

    Select express-fileupload for a simple and easy-to-use middleware that integrates seamlessly with Express.js. It is suitable for small to medium-sized applications where ease of setup and use is prioritized over advanced features.

  • busboy:

    Choose Busboy if you need a lightweight and efficient solution for handling file uploads with a focus on performance. It streams the files directly to the filesystem or memory, which is ideal for applications that require high throughput and low memory usage.

  • form-data:

    Use form-data if you need to construct and send multipart/form-data requests from Node.js. It is particularly useful for scenarios where you need to upload files to an external API or service, rather than handling incoming uploads.

  • formidable:

    Opt for Formidable if you require robust parsing capabilities and support for file uploads. It handles file uploads well and provides a rich set of features, including progress events and file size limits, making it suitable for more complex applications.

  • multer:

    Choose Multer if you are looking for a middleware that integrates directly with Express.js and provides a simple way to handle file uploads. It offers various storage options and is particularly useful for applications that need to manage uploaded files efficiently.

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