Simple express file upload middleware that wraps around busboy
Installations
npm install express-fileupload
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=12.0.0
Node Version
16.20.2
NPM Version
9.8.1
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (99.75%)
HTML (0.25%)
Developer
richardgirges
Download Statistics
Total Downloads
66,349,488
Last Day
77,022
Last Week
357,124
Last Month
1,569,158
Last Year
18,662,018
GitHub Statistics
1,539 Stars
533 Commits
261 Forks
21 Watching
6 Branches
38 Contributors
Bundle Size
31.44 kB
Minified
8.55 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.5.1
Package Id
express-fileupload@1.5.1
Unpacked Size
113.02 kB
Size
25.13 kB
File Count
35
NPM Version
9.8.1
Node Version
16.20.2
Publised On
13 Jul 2024
Total Downloads
Cumulative downloads
Total Downloads
66,349,488
Last day
1.9%
77,022
Compared to previous day
Last week
-9.7%
357,124
Compared to previous week
Last month
-0.3%
1,569,158
Compared to previous month
Last year
17.5%
18,662,018
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
express-fileupload
Simple express middleware for uploading files.
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
1# With NPM 2npm i express-fileupload 3 4# With Yarn 5yarn 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
:
1app.post('/upload', function(req, res) { 2 console.log(req.files.foo); // the uploaded file object 3});
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 filereq.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 limitreq.files.foo.size
: Uploaded size in bytesreq.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 providedhashAlgorithm
option. The property name remainsmd5
for backwards compatibility.
Examples
Using Busboy Options
Pass in Busboy options directly to the express-fileupload middleware. Check out the Busboy documentation here.
1app.use(fileUpload({ 2 limits: { fileSize: 50 * 1024 * 1024 }, 3}));
Using useTempFile Options
Use temp files instead of memory for managing the upload process.
1// Note that this option available for versions 1.0.0 and newer. 2app.use(fileUpload({ 3 useTempFiles : true, 4 tempFileDir : '/tmp/' 5}));
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 thatuseTempfiles
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 fieldtestFile
and file namecar.png
.Uploading testFile->car.png, bytes:21232...
shows current progress for each new data chunk.Upload timeout
means that no data came duringuploadTimeout
.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.
Option | Acceptable Values | Details |
---|---|---|
createParentPath |
| Automatically creates the directory path specified in .mv(filePathName) |
uriDecodeFileNames |
| Applies uri decoding to file names if set true. |
safeFileNames |
| 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 |
| 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 |
| 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 |
| Response which will be send to client if file size limit exceeded when abortOnLimit set to true. |
limitHandler |
| User defined limit handler which will be invoked if the file is bigger than configured limits. |
useTempFiles |
| 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 |
| 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. |
parseNested |
| 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 |
| Turn on/off upload process logging. Can be useful for troubleshooting. |
logger |
| Customizable logger to write debug messages to. Console is default. |
uploadTimeout |
| This defines how long to wait for data before aborting. Set to 0 if you want to turn off timeout checks. |
hashAlgorithm |
| 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
Stable Version
Stable Version
1.5.1
CRITICAL
1
9.8/10
Summary
Prototype Pollution in express-fileupload
Affected Versions
< 1.1.9
Patched Versions
1.1.9
HIGH
1
7.5/10
Summary
Express-FileUpload Arbitrary File Overwrite
Affected Versions
<= 1.3.1
LOW
5
0/10
Summary
Denial of Service in express-fileupload
Affected Versions
<= 1.0.0-alpha.1
Patched Versions
1.1.6-alpha.6
0/10
Summary
Denial of Service in express-fileupload
Affected Versions
<= 1.1.1-alpha.3
Patched Versions
1.1.6-alpha.6
0/10
Summary
Denial of Service in express-fileupload
Affected Versions
<= 1.1.2-alpha.1
Patched Versions
1.1.6-alpha.6
0/10
Summary
Denial of Service in express-fileupload
Affected Versions
<= 1.1.3-alpha.2
Patched Versions
1.1.6-alpha.6
0/10
Summary
Denial of Service in express-fileupload
Affected Versions
< 1.1.6-alpha.6
Patched Versions
1.1.6-alpha.6
Reason
security policy file detected
Details
- Info: security policy file detected: SECURITY.md:1
- Info: Found linked content: SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: SECURITY.md:1
- Info: Found text in security policy: SECURITY.md:1
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 3/9 approved changesets -- score normalized to 3
Reason
1 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 30 are checked with a SAST tool
Reason
12 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
Score
3.6
/10
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 MoreOther packages similar to express-fileupload
@types/express-fileupload
TypeScript definitions for express-fileupload
@universal-packages/express-controllers-fileupload
Express fileupload for universal controllers
@universal-packages/core-express-controllers-fileupload
Express Controllers fileupload universal-core module abstraction.
express-fileupload-validator
Validator for express-fileupload package