get post data from file upload

Posted on
  • Is it possible to get the data of a post request from within the http.createServer callback?

    http.createServer(function(req, res) {
        if (req.method == "GET") {
            // do get stuff
        } else if (req.method == "POST") {
            // save post data to sd-card
        }
    }).listen(port);
    
  • Not yet - I just created an issue for this though: https://github.com/espruino/Espruino/iss­ues/226

    You can hack around it by looking at the actual data received though:

    function pageHandler(req, res) {
      console.log(req["dRcv"].substr(req["dRcv­"].indexOf("\r\n\r\n")+4));
      res.writeHead(200, {'Content-Type': 'text/html'});
      res.write('<html><body><form method="post"><textarea name="foo"></textarea><input type="submit"></form></body></html>');
      res.end();
    }
    

    However it is an internal variable so it may change in the future.

  • Thank you. Thats exactly what i was looking for.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

get post data from file upload

Posted by Avatar for loopMasta @loopMasta

Actions