Hapi: Request.raw.req is not exactly like Node.js request object !

Created on 18 Oct 2017  ·  2Comments  ·  Source: hapijs/hapi

im using https://github.com/felixge/node-formidable package in simple node like this :

var formidable = require('formidable'),
    http = require('http'),
    util = require('util');

http.createServer(function(req, res) {
  if (req.url == '/upload' && req.method.toLowerCase() == 'post') {
    // parse a file upload
    var form = new formidable.IncomingForm();

    form.parse(req, function(err, fields, files) {
      res.writeHead(200, {'content-type': 'text/plain'});
      res.write('received upload:\n\n');
      res.end(util.inspect({fields: fields, files: files}));
    });

    return;
  }

  // show a file upload form
  res.writeHead(200, {'content-type': 'text/html'});
  res.end(
    '<form action="/upload" enctype="multipart/form-data" method="post">'+
    '<input type="text" name="title"><br>'+
    '<input type="file" name="upload" multiple="multiple"><br>'+
    '<input type="submit" value="Upload">'+
    '</form>'
  );
}).listen(8080);

and its working well also in express but when i use it in hapi i cant get response from server and .parse() callback never invoke !

my code in hapijs :

'use strict';
const Boom = require('boom');
const formidable = require('formidable');
const util = require('util');

exports.register = function (server, options, next) {

    server.route({
        method: 'POST',
        path: '/',
        config: {
            tags: ['api'],
            payload: {
                // maxBytes: 2097152000005,
                output: 'stream',
                parse: true
            }
        },
        handler: function (request, reply) {

            var form = new formidable.IncomingForm();

            form.parse(request.raw.req, function (err, fields, files) {
                reply(util.inspect({ fields: fields, files: files }));
            });

            return;
        }
    });

    next();
};

exports.register.attributes = {
    name: 'api/home'
};

[HELP WANTED]

  • node version: 6.11.4
  • hapi version: 16.6.2
  • os: Ubuntu
  • any other relevant information: no
non issue

Most helpful comment

Turn off payload parsing.

All 2 comments

Turn off payload parsing.

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

leore picture leore  ·  4Comments

andkazakov picture andkazakov  ·  5Comments

mateeyow picture mateeyow  ·  5Comments

kevinsimper picture kevinsimper  ·  4Comments

AdriVanHoudt picture AdriVanHoudt  ·  5Comments