Node.js res.end()没有触发

时间:2013-06-27 19:00:57

标签: node.js

我需要结束请求,但res.end()拒绝工作。它没有显示错误或任何内容。我需要结束请求,因为如果在处理当前请求时有另一个请求进入,则当前请求发生两次,接下来四次,依此类推。在每个后续请求中它乘以因子2。可能是什么原因?

function handler (req, res) {
console.log("Requested");
//GLOBALS.uploadReq = req;
if (req.url === '/upload' && req.method.toLowerCase() === 'post') {
// parse a file upload
//console.log();
form.uploadDir = "/var/www/newyosecrets/org_pic";

form.parse(req, function(err, fields, files) {
    //GLOBALS.uploadReq.destroy();
   req.connection.destroy();
   res.end("Ending connection");
  console.log("Checking occurence time !!");

});
req.on("end",function(){
    console.log("Request ended !! Problem is somewhere else");
});
res.on("end",function(){
    console.log("Response ended !!");
});
form.on("end",function(){
   //GLOBALS.uploadReq.destroy();
   req.connection.destroy();
   res.end();

   var z = require("myimgapi/image.js");
   var img = new z();
   img.socket = GLOBALS.socket;
   img.profSrc = GLOBALS.profPicName
   img.originalSrc = GLOBALS.orgPic;
   img.classifyWidth();


     });

form.on ('fileBegin', function(name, file){
        //Check cookie
        console.log(GLOBALS.uid);
        //Check in redis

        console.log("fileBegin:"+GLOBALS.uid);
        //rename the incoming file to the file's name
        var ext = file.name.split('.').pop();
        file.path = "/var/www/newyosecrets/org_pic" + "/" + GLOBALS.uid + "." + ((ext=="jpg" || ext=="JPG") ?"jpeg":ext);
        GLOBALS.profPicName = "/var/www/newyosecrets/profile_pic" + "/" + GLOBALS.uid + "." + ((ext=="jpg" || ext=="JPG") ?"jpeg":ext); ;
        GLOBALS.thumbPic = "/var/www/newyosecrets/thumbs/" + GLOBALS.uid + "." + ((ext=="jpg" || ext=="JPG") ?"jpeg":ext);
        GLOBALS.orgPic = "/var/www/newyosecrets/org_pic/" + GLOBALS.uid + "." + ((ext=="jpg" || ext=="JPG") ?"jpeg":ext);
        console.log("The file path is : "+file.path);
});



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

0 个答案:

没有答案