I'm writting an application which receives forms and I have a little problem. My application freezes when no files is uploading. I have no idea why. I use connect-busboy to receive files.
That's my code:
req.busboy.on('file', function(fieldname, file, filename) {
switch(fieldname){
case 'mainPhoto':
if(filename != '' && filename != null && filename != "null") {
console.log("w mainPhoto w if'ie")
var n = filename.lastIndexOf(".");
var end = filename.substring(n+1, filename.length);
mainPhoto = "mh_" + id + "." + end;
fstream = fs.createWriteStream(__dirname + '/static/photos/' + mainPhoto);
file.pipe(fstream);
fstream.on('close', function() {
console.log("End of saving hospital's main photo.");
});
break;
}
else {
mainPhoto = null
break;
}
case 'photos':
if(filename != '' && filename != null && filename != "null") {
var n = filename.lastIndexOf(".");
var end = filename.substring(n+1, filename.length);
var photohoto;
photo = "h_" + id + "_" + photosCount + "." + end;
photos.push(photo);
fstream = fs.createWriteStream(__dirname + '/static/photos/' + photo);
file.pipe(fstream);
photosCount++;
fstream.on('close', function() {
console.log("End of saving hospital's main photo.");
});
break;
}
else {
break;
}
case 'priceList':
if(filename != '' && filename != null && filename != "null") {
var n = filename.lastIndexOf(".");
var end = filename.substring(n+1, filename.length);
priceList = "pricelist_" + id + "." + end;
fstream = fs.createWriteStream(__dirname + '/static/price_lists/' + priceList);
file.pipe(fstream);
fstream.on('close', function() {
console.log("End of saving hospital's price list.");
});
break;
}
else {
priceList = null;
break;
}
}
});
I have to add all files to avoid it, but that's not the thing I wanted to do.
Any help is apprecited. Thanks!