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

Body parser maps files to params, but some time in the future #847

Closed
rehia opened this issue Jun 23, 2015 · 6 comments
Closed

Body parser maps files to params, but some time in the future #847

rehia opened this issue Jun 23, 2015 · 6 comments
Labels

Comments

@rehia
Copy link

rehia commented Jun 23, 2015

I was trying to use Restify behavior to get an uploaded file in request.params using this:

server.use(restify.bodyParser({
    mapParams: true,
    mapFiles: true,
    keepExtensions: true,
    uploadDir: '/tmp/'
}));

I have this endpoint configured:

server.post('/file', function (request, response, next) {
    console.log(request.params);
    console.log(request.files);
    response.send('OK');
    return next();
});

When I upload a file, it appears that request.files contains the file, but request.params is empty !
After a debugging session, I found in multipart_parser.js, files a read and mapped to request.params asynchronously.
I finally tries to execute the statements of the request handler in a setTimeout.
And I finally got my file mapped in request.params !

setTimeout(function () {
    console.log(request.params);
    console.log(request.files);
    response.send('OK');
    return next();
}, 100);

What can we do about this situation, so that when my handler has the control, files are set in request.params ?

Thanks

@yunong yunong added the Bug label Jun 23, 2015
@yunong yunong added this to the Release: 3.1.x milestone Jun 23, 2015
@yunong
Copy link
Member

yunong commented Jun 23, 2015

@rehia This is a bug in the multipart_parser.js as part of commit c0d1dd4. Definitely a bug here. I'll make sure this gets fixed as part of the upcoming release.

@rehia
Copy link
Author

rehia commented Jun 23, 2015

@yunong OK thanks. The comment of the commit is right, in my opinion.

@yunong
Copy link
Member

yunong commented Jun 23, 2015

@rehia Can you give me an example curl request that I can use to test a fix?

@rehia
Copy link
Author

rehia commented Jun 23, 2015

@yunong unfortunately, I don't have one. I was just trying on my computer. Nothing available.

yunong added a commit that referenced this issue Jun 25, 2015
@yunong
Copy link
Member

yunong commented Jun 25, 2015

This has been fixed as per c604cd8. If you pick up #master you'll get the fix right away.

@yunong yunong closed this as completed Jun 25, 2015
@rehia
Copy link
Author

rehia commented Jun 26, 2015

@yunong OK thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants