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;
});
on my screen i see
Upload Code Hit!
33333!
88888
Upload Code Hit2222!
form. parse ends
ie I am not getting the log
console.log(" form.in(end) hit ")
which gives me impression that the end event is not getting fired . However I have waited for 30 min & image is captured by camera in low quality. I am using phonegap android application to send image on local server & so i belive even 30 in for local server is too much .
What am i missing ?
EDIT1:
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 ?