formidable: Error: MultipartParser.end(): stream ended unexpectedly: state = START #79

I am new to node.js . I have created a node.js server which accepts post requests . I am using phonegap android application to send image on local server.

error: Error: MultipartParser.end(): stream ended unexpectedly: state = START

Snippet of code is as shown below . My form.on(‘end’ … is not getting called and there by my image is not getting uploaded on to the server

app.post(‘/upload’, function(req, res) {

        console.log("Upload Code Hit!")

        var form = new formidable.IncomingForm();
        form.parse(req, function(err, fields, files) {
                        console.log("Upload Code Hit2222!")
                        res.writeHead(200, {'content-type': 'text/plain'});
                        res.write('received upload:\n\n');

                        res.end(util.inspect({fields: fields, files: files}));

                        console.log(" form. parse ends ")
                });
        console.log("33333!")
        form.on('end', function(fields, files) {
                console.log(" form.in(end) hit ")
                /* Temporary location of our uploaded file */
                var temp_path = this.openedFiles[0].path;
                /* The file name of the uploaded file */

                var file_name=this.openedFiles[0].name;
                /* Location where we want to copy the uploaded file */
                var new_location = './uploadedFOlder/';

                fs.copy(temp_path, new_location + file_name, function(err) {
                        if (err) {
                        console.error(err);
                        } else {
                        console.log("success!")
                        }
                        });
                });

                console.log("88888")

return;

});

i got Upload Code Hit! 33333! 88888 Upload Code Hit2222! form. parse ends ie I am not getting the log

console.log(" form.in(end) hit ")

I added a code

form.on(‘error’, function(err) { console.log(‘ERROR!’+ err); res.end(); }); and it shows

ERROR!Error: MultipartParser.end(): stream ended unexpectedly: state = START can some one please help me what i am doing wrong ?

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 16 (6 by maintainers)

Most upvoted comments

Prove it.

i catched the exception too,did u solved,?