Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When no query params are sent, request.params is null instead of {}. #1324

Closed
blindMoe opened this issue Jan 14, 2014 · 1 comment
Closed
Assignees
Labels
bug Bug or defect
Milestone

Comments

@blindMoe
Copy link

When no query params are sent, request.params is null instead of {}.

My route:

{
  method: 'POST',
  path: '/fileUpload',
  config: {
    handler: Handlers.fileUpload, 
    validate: {
      payload: {
        name: Hapi.types.String().required(),
        id: Hapi.types.Number().optional().min(100).max(999999999),
        uploadFile: Hapi.types.Object().optional()
      }
    }
  }
}

My Handler:

exports.fileUpload = function(request, reply) {
  //console.log("rawPayload: " + request.rawPayload);
  console.log("Received POST from " + request.payload.name + "; id=" + (request.payload.id || 'anon'));

  if (request.payload && request.payload.uploadFile) {
    var f = request.payload.uploadFile;
    console.log("uploadFile " + f.originalFilename + " (" + f.size + " bytes) at " + f.path);
    console.log("that you should persist to storage and remove from temp folder");
    // Use fs for this one: http://nodejs.org/api/fs.html
    Fs.unlink(f.path, function (err) {
        if (err) throw err;
            console.log('successfully deleted ' + f.path);
    });
  }

  reply({ 
    greeting: 'POST hello to ' + request.payload.name
  });
}

Instead of doing: if (request.payload.uploadFile) {

I am force to do: if (request.payload && request.payload.uploadFile) {

@ghost ghost assigned hueniverse Jan 14, 2014
@hueniverse
Copy link
Contributor

Actually, query shows up under request.query not request.params (which contains path parameters). But either way this was a bug.

jmonster pushed a commit to jmonster/hapi that referenced this issue Feb 10, 2014
@lock lock bot locked as resolved and limited conversation to collaborators Jan 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants