Last active
October 19, 2016 14:21
-
-
Save nvcexploder/053b4b28429ef9675546 to your computer and use it in GitHub Desktop.
Revisions
-
nvcexploder revised this gist
Sep 15, 2014 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -20,7 +20,7 @@ var routeConfig = { //create whatever writestream you want var image = Fs.createWriteStream(request.payload.file.hapi.filename); image.on('finish', function () { reply({status: 'ok!'}); }); -
nvcexploder revised this gist
Sep 15, 2014 . 2 changed files with 11 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ $ npm install hapi joi #A good way to test is this: $ curl --form file=@lulz.png localhost:8080/selfies This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,10 +16,15 @@ var routeConfig = { allow: 'multipart/form-data' }, handler: function (request, reply) { //create whatever writestream you want var image = Fs.createWriteStream(request.payload.file.hapi.filename); image.on('finish', function (err) { reply({status: 'ok!'}); }); request.payload.file.pipe(image); } } -
nvcexploder created this gist
Sep 15, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ var Hapi = require('hapi'); var Fs = require('fs'); var Joi = require('joi'); var server = new Hapi.Server(8080); var routeConfig = { validate: { payload: { file: Joi.string().required().description('file name for picture upload') } }, payload: { output: 'stream', parse: true, allow: 'multipart/form-data' }, handler: function (request, reply) { var image = Fs.createWriteStream(request.payload.file.hapi.filename); request.payload.file.pipe(image); reply({status: 'ok'}); } } server.route({ method: 'POST', path: '/selfies', config: routeConfig }); server.start(function (err) { console.log('oh word?'); });