express-fileupload
Advanced tools
Comparing version 0.3.0 to 0.4.0
@@ -6,2 +6,3 @@ 'use strict'; | ||
const streamifier = require('streamifier'); | ||
const md5 = require('md5'); | ||
@@ -77,2 +78,9 @@ const ACCEPTABLE_MIME = /^(?:multipart\/.+)$/i; | ||
file.on('limit', () => { | ||
if (options.abortOnLimit) { | ||
res.writeHead(413, {'Connection': 'close'}); | ||
res.end('File size limit has been reached'); | ||
} | ||
}); | ||
file.on('data', function(data) { | ||
@@ -138,3 +146,5 @@ buffers.push(data); | ||
encoding: encoding, | ||
truncated: file.truncated, | ||
mimetype: mime, | ||
md5: md5(buf), | ||
mv: function(path, callback) { | ||
@@ -162,4 +172,4 @@ // Callback is passed in, use the callback API | ||
* Takes two function arguments to make it compatible w/ Promise or Callback APIs | ||
* @param {Function} successFunc | ||
* @param {Function} errorFunc | ||
* @param {Function} successFunc | ||
* @param {Function} errorFunc | ||
*/ | ||
@@ -166,0 +176,0 @@ function doMove(successFunc, errorFunc) { |
{ | ||
"name": "express-fileupload", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"author": "Richard Girges <richardgirges@gmail.com>", | ||
@@ -15,2 +15,3 @@ "description": "Simple express file upload middleware that wraps around Busboy", | ||
"fs-extra": "^4.0.1", | ||
"md5": "^2.2.1", | ||
"streamifier": "^0.1.1" | ||
@@ -17,0 +18,0 @@ }, |
@@ -43,2 +43,3 @@ # express-fileupload | ||
* `req.files.foo.data`: A buffer representation of your file | ||
* `req.files.foo.truncated`: A boolean that represents if the file is over the size limit | ||
@@ -124,2 +125,3 @@ ### Full Example | ||
preserveExtension | <ul><li><code>false</code> **(default)**</li><li><code>true</code></li><li><code>*Number*</code></li></ul> | Preserves filename extension when using <code>safeFileNames</code> option. If set to <code>true</code>, will default to an extension length of 3. If set to <code>*Number*</code>, 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.<br /><br />**Example #1 (true):**<br /><code>app.use(fileUpload({ safeFileNames: true, preserveExtension: true }));</code><br />*myFileName.ext* --> *myFileName.ext*<br /><br />**Example #2 (max extension length 2, extension shifted):**<br /><code>app.use(fileUpload({ safeFileNames: true, preserveExtension: 2 }));</code><br />*myFileName.ext* --> *myFileNamee.xt* | ||
abortOnLimit | <ul><li><code>false</code> **(default)**</li><li><code>true</code></ul> | Returns a HTTP 413 when the file is bigger than the size limit if true. Otherwise, it will add a <code>truncate = true</code> to the resulting file structure. | ||
@@ -126,0 +128,0 @@ # Help Wanted |
@@ -95,2 +95,15 @@ 'use strict'; | ||
app.all('/upload/single/truncated', function(req, res) { | ||
if (!req.files) { | ||
return res.status(400).send('No files were uploaded.'); | ||
} | ||
if (req.files.testFile.truncated) { | ||
// status 400 to differentiate from ending the request in the on limit | ||
return res.status(400).send(`File too big`); | ||
} | ||
return res.status(200).send('Upload succeed'); | ||
}); | ||
app.all('/upload/multiple', function(req, res) { | ||
@@ -97,0 +110,0 @@ if (!req.files) { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1222529
21
932
131
4
+ Addedmd5@^2.2.1
+ Addedcharenc@0.0.2(transitive)
+ Addedcrypt@0.0.2(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedmd5@2.3.0(transitive)