diff --git a/lib/cloud/cloud.js b/lib/cloud/cloud.js index 9c73743..055f54d 100644 --- a/lib/cloud/cloud.js +++ b/lib/cloud/cloud.js @@ -37,12 +37,20 @@ var cloud = { next(); }); - app.use(multer({ dest: '/tmp'})); + var storage = multer.diskStorage({ + destination: function (req, file, cb) { + cb(null, '/tmp') + }, + filename: function (req, file, cb) { + cb(null, file.originalname) + } + }) + var upload = multer({storage: storage}) app.use(bodyParser.json({"limit": "10mb"})); // Process GETs, POSTs, and everything else inbetween! // Do clever jsonp stuff, and make one unified params object - app.all('/:func', function (req, res) { + app.all('/:func', upload.any(), function (req, res) { var params = {}; params = paramsUtils.normalise(params, req); return cloud.callFunction(params, req, res); diff --git a/lib/common/requestValidator.js b/lib/common/requestValidator.js index 6c2078f..07f0bd7 100644 --- a/lib/common/requestValidator.js +++ b/lib/common/requestValidator.js @@ -140,7 +140,7 @@ module.exports = function(request){ for(var fileEntry in filesInRequest){ params.submission.fileStream = filesInRequest[fileEntry].path; - params.submission.fileName = filesInRequest[fileEntry].name;// In this case, the name is the hash name "filePlaceHolder325346234234634646" + params.submission.fileName = filesInRequest[fileEntry].filename;// In this case, the name is the hash name "filePlaceHolder325346234234634646" } return cb(undefined, params); diff --git a/lib/mbaas.js b/lib/mbaas.js index 5d8ea1c..a09e978 100644 --- a/lib/mbaas.js +++ b/lib/mbaas.js @@ -166,11 +166,20 @@ function handleError(err, res){ // connect.router(function (app) { var app = express.Router(); app.use(cors()); - app.use(multer({ dest: '/tmp'})); app.use(bodyParser.json({"limit": "10mb"})); app.use(bodyParser.urlencoded({ extended: false })); - app.post('/:api', handleRequest); + var storage = multer.diskStorage({ + destination: function (req, file, cb) { + cb(null, '/tmp') + }, + filename: function (req, file, cb) { + cb(null, file.originalname) + } + }) + var upload = multer({storage: storage}) + + app.post('/:api', upload.any(), handleRequest); app.get('/sync/stats', function(req, res){ if (fh.sync && fh.sync.getStats) { @@ -296,7 +305,7 @@ var app = express.Router(); }); }); - app.post('/forms/:appId/:submitId/:fieldId/:fileId/submitFormFile', function(req, res){ + app.post('/forms/:appId/:submitId/:fieldId/:fileId/submitFormFile', upload.any(), function(req, res){ var requestValidator = reqValidator(req); applyAuth(req, res, "forms", undefined, function(err, ok){ @@ -316,7 +325,7 @@ var app = express.Router(); }); }); - app.post('/forms/:appId/:submitId/:fieldId/:fileId/submitFormFileBase64', function(req, res){ + app.post('/forms/:appId/:submitId/:fieldId/:fileId/submitFormFileBase64', upload.any(), function(req, res){ var requestValidator = reqValidator(req); applyAuth(req, res, "forms", undefined, function(err, ok){ diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index 8142b01..f806c25 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,6 +1,6 @@ { "name": "fh-mbaas-express", - "version": "5.9.2", + "version": "5.10.0", "dependencies": { "async": { "version": "0.2.9", @@ -90,7 +90,7 @@ "dependencies": { "unpipe": { "version": "1.0.0", - "from": "unpipe@>=1.0.0 <1.1.0", + "from": "unpipe@1.0.0", "resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz" } } @@ -138,7 +138,7 @@ "dependencies": { "mime-types": { "version": "2.1.17", - "from": "mime-types@>=2.1.16 <2.2.0", + "from": "mime-types@>=2.1.15 <2.2.0", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz", "dependencies": { "mime-db": { @@ -344,7 +344,7 @@ }, "statuses": { "version": "1.3.1", - "from": "statuses@>=1.3.1 <1.4.0", + "from": "statuses@>=1.3.1 <2.0.0", "resolved": "https://registry.npmjs.org/statuses/-/statuses-1.3.1.tgz" }, "type-is": { @@ -764,13 +764,18 @@ } }, "multer": { - "version": "0.1.8", - "from": "multer@0.1.8", - "resolved": "https://registry.npmjs.org/multer/-/multer-0.1.8.tgz", + "version": "1.3.0", + "from": "multer@1.3.0", + "resolved": "https://registry.npmjs.org/multer/-/multer-1.3.0.tgz", "dependencies": { + "append-field": { + "version": "0.1.0", + "from": "append-field@>=0.1.0 <0.2.0", + "resolved": "https://registry.npmjs.org/append-field/-/append-field-0.1.0.tgz" + }, "busboy": { "version": "0.2.14", - "from": "busboy@>=0.2.9 <0.3.0", + "from": "busboy@>=0.2.11 <0.3.0", "resolved": "https://registry.npmjs.org/busboy/-/busboy-0.2.14.tgz", "dependencies": { "dicer": { @@ -814,20 +819,93 @@ } } }, + "concat-stream": { + "version": "1.6.0", + "from": "concat-stream@>=1.5.0 <2.0.0", + "resolved": "https://registry.npmjs.org/concat-stream/-/concat-stream-1.6.0.tgz", + "dependencies": { + "inherits": { + "version": "2.0.3", + "from": "inherits@>=2.0.3 <3.0.0", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz" + }, + "typedarray": { + "version": "0.0.6", + "from": "typedarray@>=0.0.6 <0.0.7", + "resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz" + }, + "readable-stream": { + "version": "2.3.3", + "from": "readable-stream@>=2.2.2 <3.0.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.3.tgz", + "dependencies": { + "core-util-is": { + "version": "1.0.2", + "from": "core-util-is@>=1.0.0 <1.1.0", + "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz" + }, + "isarray": { + "version": "1.0.0", + "from": "isarray@>=1.0.0 <1.1.0", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz" + }, + "process-nextick-args": { + "version": "1.0.7", + "from": "process-nextick-args@>=1.0.6 <1.1.0", + "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-1.0.7.tgz" + }, + "safe-buffer": { + "version": "5.1.1", + "from": "safe-buffer@>=5.1.1 <5.2.0", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz" + }, + "string_decoder": { + "version": "1.0.3", + "from": "string_decoder@>=1.0.3 <1.1.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.0.3.tgz" + }, + "util-deprecate": { + "version": "1.0.2", + "from": "util-deprecate@>=1.0.1 <1.1.0", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz" + } + } + } + } + }, "mkdirp": { - "version": "0.3.5", - "from": "mkdirp@>=0.3.5 <0.4.0", - "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.3.5.tgz" + "version": "0.5.1", + "from": "mkdirp@>=0.5.1 <0.6.0", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "dependencies": { + "minimist": { + "version": "0.0.8", + "from": "minimist@0.0.8", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz" + } + } }, - "qs": { - "version": "1.2.2", - "from": "qs@>=1.2.2 <1.3.0", - "resolved": "https://registry.npmjs.org/qs/-/qs-1.2.2.tgz" + "object-assign": { + "version": "3.0.0", + "from": "object-assign@>=3.0.0 <4.0.0", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz" + }, + "on-finished": { + "version": "2.3.0", + "from": "on-finished@>=2.3.0 <2.4.0", + "resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.3.0.tgz", + "dependencies": { + "ee-first": { + "version": "1.1.1", + "from": "ee-first@1.1.1", + "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz" + } + } }, "type-is": { - "version": "1.5.7", - "from": "type-is@>=1.5.2 <1.6.0", - "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.5.7.tgz", + "version": "1.6.15", + "from": "type-is@>=1.6.4 <2.0.0", + "resolved": "https://registry.npmjs.org/type-is/-/type-is-1.6.15.tgz", "dependencies": { "media-typer": { "version": "0.3.0", @@ -835,18 +913,23 @@ "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz" }, "mime-types": { - "version": "2.0.14", - "from": "mime-types@>=2.0.9 <2.1.0", - "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.0.14.tgz", + "version": "2.1.17", + "from": "mime-types@>=2.1.15 <2.2.0", + "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.17.tgz", "dependencies": { "mime-db": { - "version": "1.12.0", - "from": "mime-db@>=1.12.0 <1.13.0", - "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.12.0.tgz" + "version": "1.30.0", + "from": "mime-db@>=1.30.0 <1.31.0", + "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.30.0.tgz" } } } } + }, + "xtend": { + "version": "4.0.1", + "from": "xtend@>=4.0.0 <5.0.0", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz" } } }, diff --git a/package.json b/package.json index 4740ae1..7ab9c45 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fh-mbaas-express", - "version": "5.9.2", + "version": "5.10.0", "description": "FeedHenry MBAAS Express", "main": "lib/webapp.js", "dependencies": { @@ -11,7 +11,7 @@ "fh-amqp-js": "0.7.1", "fh-mbaas-client": "0.16.5", "fh-reportingclient": "0.5.7", - "multer": "0.1.8", + "multer": "1.3.0", "request": "2.81.0", "type-is": "~1.2.1", "underscore": "1.5.1" diff --git a/sonar-project.properties b/sonar-project.properties index 428caf5..637e84b 100644 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -1,6 +1,6 @@ sonar.projectKey=fh-mbaas-express sonar.projectName=fh-mbaas-express-nightly-master -sonar.projectVersion=5.9.2 +sonar.projectVersion=5.10.0 sonar.sources=./lib sonar.tests=./test diff --git a/test/unit/test_requestValidator.js b/test/unit/test_requestValidator.js index 1a0c658..7a812ee 100644 --- a/test/unit/test_requestValidator.js +++ b/test/unit/test_requestValidator.js @@ -108,7 +108,7 @@ module.exports = { "files": [ { "path": "/some/file/path", - "name": "somefileName" + "filename": "somefileName" } ] };