title: nodejs formidable changing uploadDir
body: <p>i have a proyect that im trying to finish i wanna upload images
  i can upload the images but not in the dir that supose to upload </p>
  
  <p>ok lets code:</p>
  
  <pre><code> app.post('/register',function(req,res) 
      {
  var form = new formidable.IncomingForm();
  form.keepExtensions = true;
  form.uploadDir ='./uploaded/';
  form
      .on('error', function(err) {
          throw err;
      })
  
      .on('field', function(field, value) {
          //receive form fields here
      })
  
      /* this is where the renaming happens */
      .on ('fileBegin', function(name, file){
              //rename the incoming file to the file's name
              file.path = form.uploadDir + "/" + file.name;
      })
  
      .on('file', function(field, file) {
          //On file received
      })
  
      .on('progress', function(bytesReceived, bytesExpected) {
          //self.emit('progess', bytesReceived, bytesExpected)
  
          var percent = (bytesReceived / bytesExpected * 100) | 0;
          process.stdout.write('Uploading: %' + percent + '\r');
      })
  
      .on('end', function() {
  
  
      });
  
  form.parse(req);
  </code></pre>
  
  <p>the problem is that when i post the image... the image still saving on process.env.TMP
  my proyect has this dir arq</p>
  
  <pre><code>proyect:
      node_modules
      uploaded
      public
      routes
      views
      app.js
      package.json
  </code></pre>
  
  <p>EDIT 2: PROBLEM IS BODYPARSER</p>
  
  <p>ok from the last code... the problem was the app.js when i configure the app has a bodyParser so that bodyParser method use formidable from the express</p>
  
  <p>the last code is right and functionally, if anybody wanna use the code... just comment the line from express.configure</p>
  
  <pre><code>app.use(express.bodyParser());
  </code></pre>
  
  <p>to turn off the express bodyparser but express use formidable too so is same thing... </p>
  
  <p>there is another problem</p>
  
  <p>i configure express.bodyParser like this</p>
  
  <pre><code>  app.use(express.bodyParser(
      {
        uploadDir: './uploads',
        keepExtensions: true
      }));
  </code></pre>
  
  <p>i change the first code like this</p>
  
  <pre><code>app.post('/register',function(req,res) 
  {
    var oldDir=req.files.img.path;
    var newDir='./uploads/'+req.body.email+'/perfil/';
  
  if(req.files)
  {
    mkdirp(newDir,0777,function(err){
      if(err) throw err;
    })
  }
  if(req.files)
  {
    fs.rename(oldDir,newDir+req.files.img.name,function(err){
      if(err) throw err;
    });
  
  }
  res.send('pow!');
  </code></pre>
  
  <p>it is functionally and when this code receive a file put the file in the uploads folder next create folder with the name of the email and last move the file into the email folder and rename it like the origin file with the extension</p>
  
  <p>its perfect"!</p>
  
  <p>nooo there is no perfection... i wanna use this methods</p>
  
  <pre><code>.on ('fileBegin', function(name, file){
              //rename the incoming file to the file's name
              file.path = form.uploadDir + "/" + file.name;
      })
      .on('progress', function(bytesReceived, bytesExpected) {
          //self.emit('progess', bytesReceived, bytesExpected)
  
          var percent = (bytesReceived / bytesExpected * 100) | 0;
          process.stdout.write('Uploading: %' + percent + '\r');
      })
  </code></pre>
  
  <p>because from the first code i can configure where put the file from the beginning
  in the second code i move the file after the server receive the file</p>
  
  <p>i think the method is in express because express use formidable like middleware</p>
  
  <p>how can i configure the method on??</p>
  
  <p>where is the method...?'?</p>
  
  <p>how can i know the methods contained in req.files from the second code??
  (because req.files using bodyParser() is same like form.file using formidable in first code)</p>
  
  <p>tnx all</p>