Comparing version 0.0.4 to 0.0.5
42
index.js
var os = require('os'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var crypto = require('crypto'); | ||
@@ -13,6 +14,9 @@ var Busboy = require('busboy'); | ||
var dest; | ||
// some users may ommit the trailing slash | ||
if (options.dest) { dest = options.dest.slice(-1) == '/' ? options.dest : options.dest + '/'; } | ||
else { dest = os.tmpdir(); } | ||
if (options.dest) { | ||
dest = options.dest; | ||
} else { | ||
dest = os.tmpdir(); | ||
} | ||
// make sure the dest dir exists | ||
@@ -45,3 +49,11 @@ mkdirp(dest, function(err) { if (err) throw err; }); | ||
busboy.on('field', function(fieldname, val, valTruncated, keyTruncated) { | ||
req.body[fieldname] = val; | ||
if (req.body.hasOwnProperty(fieldname)) { | ||
if (Array.isArray(req.body)) { | ||
req.body[fieldname].push(val); | ||
} else { | ||
req.body[fieldname] = [req.body[fieldname], val]; | ||
} | ||
} else { | ||
req.body[fieldname] = val; | ||
} | ||
}); | ||
@@ -52,6 +64,16 @@ | ||
var ext = '.' + filename.split('.').slice(-1)[0]; | ||
var newFilename = rename(fieldname, filename.replace(ext, '')) + ext; | ||
var path = dest + newFilename; | ||
var ext, newFilename, newFilePath; | ||
if (filename) { | ||
ext = '.' + filename.split('.').slice(-1)[0]; | ||
newFilename = rename(fieldname, filename.replace(ext, '')) + ext; | ||
newFilePath = path.join(dest, newFilename); | ||
} | ||
else { | ||
filename = null; | ||
ext = null; | ||
newFilename = null; | ||
newFilePath = '/dev/null'; // do something for Windows! | ||
} | ||
var file = { | ||
@@ -63,4 +85,4 @@ fieldname: fieldname, | ||
mimetype: mimetype, | ||
path: path, | ||
extension: ext.replace('.', '') | ||
path: newFilePath, | ||
extension: (ext === null) ? null : ext.replace('.', '') | ||
}; | ||
@@ -71,3 +93,3 @@ | ||
var ws = fs.createWriteStream(path); | ||
var ws = fs.createWriteStream(newFilePath); | ||
fileStream.pipe(ws); | ||
@@ -74,0 +96,0 @@ |
{ | ||
"name": "multer", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Connect middleware for handling multipart/form-data", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
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
529377
16
174