Created
October 7, 2015 20:30
-
-
Save InTheCloudDan/f79a08980125eefe884b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
method: 'POST', | |
path: '/hello', | |
config: require('../../index.js').postHelloConfig, | |
handler: require('../../controllers/helloPostHandler.js').helloPostHandler | |
} | |
var postHelloConfig = { | |
auth: 'false', | |
payload: { | |
output: 'file', | |
maxBytes: 209715200, | |
allow: 'multipart/form-data' | |
}, | |
validate: { | |
payload: { | |
name: Joi.string().min(1).required(), | |
id: Joi.number().min(100).max(999999999), | |
output: 'file', | |
parse: true, | |
uploadFile: Joi.object().optional() | |
} } | |
}; | |
exports.helloPostHandler = function (request, reply) { | |
console.log("Session: %j", request.payload); | |
//console.log("Received POST from " + request.payload.name + "; id=" + (request.payload.id || 'anon')); | |
if (request.payload.uploadFile) { | |
Fs.readFile(request.payload.uploadFile.path, function readfile(err, data) { | |
var filename = request.payload.uploadFile.filename; | |
//var f = request.payload.uploadFile; | |
console.log(filename); | |
var dPath = __dirname + '/uploads/' + filename; | |
Fs.writeFile(dPath, data, function(err) { | |
if (err) return reply(err); | |
}); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment