title: How To Upload Multiple Image from Android to NodeJS server
body: <p>I recently saw a tutorial to upload some photos from here [<a href="https://aguacatelang.wordpress.com/2012/08/19/android-multipart-upload-to-node-js/][1]" rel="nofollow">https://aguacatelang.wordpress.com/2012/08/19/android-multipart-upload-to-node-js/][1]</a></p>
  
  <p>I've just learned nodejs and less understanding of the structure of programming languages, I found a mistake like this :</p>
  
  <pre><code>home/je/Documents/BE/UploadFoto/app.js:12
  var db = new Db('photos', new dbServer('localhost', dbConnection.'27017', {}))
                                                                   ^^^^^^^
  SyntaxError: Unexpected string
      at Module._compile (module.js:439:25)
      at Object.Module._extensions..js (module.js:474:10)
      at Module.load (module.js:356:32)
      at Function.Module._load (module.js:312:12)
      at Function.Module.runMain (module.js:497:10)
      at startup (node.js:119:16)
      at node.js:935:3
  </code></pre>
  
  <p>this is original source code :</p>
  
  <pre><code>var express = require('express');
  
  var app = express()
  
  var fs = require('fs');
  var im = require('imagemagick');
  
  var Db = require('mongodb').Db;
  var dbServer = require('mongodb').Server;
  var dbConnection = require('mongodb').Connection;
  
  var db = new Db('photos', new dbServer('localhost', dbConnection.'DEFAULT_PORT', {}));
  db.open(function(err, db){});
  
  app.use(express.bodyParser())
  
  app.get('/', function(req, res){
      res.send(
          '&lt;form action="/upload" method="post" enctype="multipart/form-data"&gt;'+
          '&lt;input type="file" name="source"&gt;'+
          '&lt;input type="submit" value="Upload"&gt;'+
          '&lt;/form&gt;'
      );
  });
  
  app.post('/upload', function(req, res){
      console.log("Received file:\n" + JSON.stringify(req.files));
  
      var photoDir = __dirname+"/photos/";
      var thumbnailsDir = __dirname+"/photos/thumbnails/";
      var photoName = req.files.source.name;
  
      fs.rename(
          req.files.source.path,
          photoDir+photoName,
          function(err){
              if(err != null){
                  console.log(err)
                  res.send({error:"Server Writting No Good"});
              } else {
                  im.resize(
                      {
                          srcData:fs.readFileSync(photoDir+photoName, 'binary'),
                          width:256
                      }, 
                      function(err, stdout, stderr){
                          if(err != null){
                              console.log('stdout : '+stdout)
  
                              res.send({error:"Resizeing No Good"});
                          } else {
                              //console.log('ELSE stdout : '+stdout)
                              fs.writeFileSync(thumbnailsDir+"thumb_"+photoName, stdout, 'binary');
                              res.send("Ok");
                          }
                      }
                  );
              }
          }
      );
  });
  
  app.get('/info', function(req, res){
      console.log(__dirname);
      res.send("ok");
  });
  
  app.listen(8000);
  console.log('connected to localhost....')
  </code></pre>
  
  <p>I switched  DEFAULT_PORT to 27017 because in my PC the port that is used mongodb:localhost/27017. May someone help me? thanks</p>