How do you extract form data (form[method="post"]
) and file uploads sent from the HTTP POST
method in Node.js?
I've read the documentation, googled and found nothing.
function (request, response) {
//request.post????
}
Is there a library or a hack?
For those using raw binary POST upload without encoding overhead you can use:
client:
server:
If you use Express (high-performance, high-class web development for Node.js), you can do this:
HTML:
JavaScript:
UPDATED on 1/June/2016:
Method above is deprecated use now:
Here's a very simple no-framework wrapper based on the other answers and articles posted in here:
Usage example:
Limit POST size avoid flood your node app. There is a great raw-body module, suitable both for express and connect, that can help you limit request by size and length.
You can use the
querystring
module:Now, for example, if you have an
input
field with nameage
, you could access it using the variablepost
:For anyone wondering how to do this trivial task without installing a web framework I managed to plop this together. Hardly production ready but it seems to work.