Search code examples
node.jsformidable

How form.parse() method works?


I have a doubt on how form.parse() in the below scenario works. what does it mean by fields and files from the form.parse(). I kind of not understand properly and exactly how formidable Module as well.

  http.createServer(function (req, res){

        if (req.url == '/fileupload'){
            var form = new formidable.IncomingForm();
            form.parse(req, function(err,fields,files)) // doubt on how this parsing works 
        }
        res.writeHead(200,{'content-Type': 'text/html'});
        res.write('<form action="fileupload" method="post" enctype="multipart/form-data">');
        res.write('<input type="file" name="fileupload"><br>');
        res.write('<input type="submit"');
        res.write('</form>');

    }).listen(8080);

Solution

  • I have gone through the specification mentioned in github regarding form.parse. Here form.parse is adopting the default call back function.

    We can override the call function according to our requirement and then we would have access to all of our form fields and files.

    Kindly refer the below mentioned link to get the detailed explanation.

    Please refer : https://github.com/felixge/node-formidable