Simple express middleware for uploading files.
Version 1.1.1 Breaking Changes
Breaking change to
md5value contains md5 hash instead of a function to compute it.
md5now can be used with
Version 1.0.0 Breaking Changes
Breaking change to
md5 handling. Read about it here.
# With NPMnpm install --save express-fileupload# With Yarnyarn add express-fileupload
When you upload a file, the file will be accessible from
- 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
The req.files.foo object will contain the following:
req.files.foo.mv: A function to move the file elsewhere on your server
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
Using Busboy Options
Pass in Busboy options directly to the express-fileupload middleware. Check out the Busboy documentation here.
Using useTempFile Options
Use temp files instead of memory for managing the upload process.
Pass in non-Busboy options directly to the middleware. These are express-fileupload specific options.
||Automatically creates the directory path specified in
||Applies uri decoding to file names if set true.|
||Strips characters from the upload's filename. You can use custom regex to determine what to strip. If set to
Example #1 (strip slashes from file names):
||Preserves filename extension when using
Example #1 (true):
myFileName.ext --> myFileName.ext
Example #2 (max extension length 2, extension shifted):
myFileName.ext --> myFileNamee.xt
||Returns a HTTP 413 when the file is bigger than the size limit if true. Otherwise, it will add a
||Response which will be send to client if file size limit exceeded when abortOnLimit set to true.|
||User defined limit handler which will be invoked if the file is bigger than configured limits.|
||Will use temporary files at the specified tempDir for managing uploads rather than using buffers in memory. This avoids memory issues when uploading large files.|
||Used with the
||By default, req.body and req.files are flattened like this:
When this option is enabled they are parsed in order to be nested like this:
Looking for additional maintainers. Please contact
richardgirges [ at ] gmail.com if you're interested. Pull Requests are welcomed!