Skip to content

Instantly share code, notes, and snippets.

@nvcexploder
Last active October 19, 2016 14:21
Show Gist options
  • Select an option

  • Save nvcexploder/053b4b28429ef9675546 to your computer and use it in GitHub Desktop.

Select an option

Save nvcexploder/053b4b28429ef9675546 to your computer and use it in GitHub Desktop.

Revisions

  1. nvcexploder revised this gist Sep 15, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion server.js
    Original 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 (err) {
    image.on('finish', function () {
    reply({status: 'ok!'});
    });

  2. nvcexploder revised this gist Sep 15, 2014. 2 changed files with 11 additions and 2 deletions.
    4 changes: 4 additions & 0 deletions command line stuff
    Original 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
    9 changes: 7 additions & 2 deletions server.js
    Original 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);
    reply({status: 'ok'});
    }
    }

  3. nvcexploder created this gist Sep 15, 2014.
    31 changes: 31 additions & 0 deletions server.js
    Original 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?');
    });