# How can I get on server an uploaded picture (using ngCordova) from Ionic app?

**URL:** <https://forum.ionicframework.com/t/how-can-i-get-on-server-an-uploaded-picture-using-ngcordova-from-ionic-app/18411>\
**Category:** cordova\
**Created:** [February 28, 2015, 4:27pm UTC](https://forum.ionicframework.com/t/how-can-i-get-on-server-an-uploaded-picture-using-ngcordova-from-ionic-app/18411 "2015-02-28T16:27:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![svecax](https://avatars.discourse-cdn.com/v4/letter/s/a9adbd/32.png) [@svecax](https://forum.ionicframework.com/u/svecax)\
**Post date:** [February 28, 2015, 4:27pm UTC](https://forum.ionicframework.com/t/how-can-i-get-on-server-an-uploaded-picture-using-ngcordova-from-ionic-app/18411/1 "2015-02-28T16:27:36Z")

</div>

Hi! I use this function to upload an image to a server running node.js and express.

```
var uploadPhoto = function(imageURI) {
  var server = "http://192.168.1.62:8080/upload";
  var filePath = imageURI;
  var options = {};

  $cordovaFileTransfer.upload(server, filePath, options).then(function (result) {
    //
  }, function (err) {
    alert('error');
  }, function(progress) {
    //
  });
};

```

First question: What properties should be added to the **options** object above?  
Second question: How can I get the image on the server?

```
router.post('/upload', function(req, res, next) {

  // How can I extract the image from the request (and save it)?
  // I have to mention that: req.body = {};
  res.send("ok");
});
```

---

<div class="post-metadata">

**Author:** ![yurinondual](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/yurinondual/32/92490_2.png) [@yurinondual](https://forum.ionicframework.com/u/yurinondual)\
**Post date:** [February 28, 2015, 9:39pm UTC](https://forum.ionicframework.com/t/how-can-i-get-on-server-an-uploaded-picture-using-ngcordova-from-ionic-app/18411/2 "2015-02-28T21:39:00Z")

</div>

If you are using express, then use **connect-multiparty** module. And in your code do something like this (This is example from y app where I upload file to amazon):

In my node controller:

```
uploadService.upload(req.files.file, req.files.file.name,
    function(fileObj){
      return res.jsonp(fileObj);
    },
    function(err){
      return res.jsonp(500, err);
    }
  ); 

```

And my uploadService

```
module.exports = {

```

upload: function(file, name, success, error) {  
var path = file.path;  
var destFileName = shortId.generate()+’.’+mime.extension(file.type);

```
if (name) {
  var b = new Buffer(name);
  var s = b.toString('base64');
  destFileName = s+'.'+mime.extension(file.type);
}

fs.stat(path, function(err, file_info) {
  var bodyStream = fs.createReadStream( path );

  var params = {
    Bucket: bucket,
    ACL: 'public-read',
    Key: destFileName,
    ContentLength : file_info.size,
    Body: bodyStream
  };

  s3.putObject(params, function(err, data) {
    if (err) {
      error(err);
    } else {
      success({
        url: util.format('http://%s.s3.amazonaws.com/%s', bucket, destFileName),
        key: destFileName,
        size: file_info.size
      });
    }
  });

});
},
```

---

<div class="post-metadata">

**Author:** ![luisito95](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@luisito95](https://forum.ionicframework.com/u/luisito95)\
**Post date:** [August 24, 2015, 6:46pm UTC](https://forum.ionicframework.com/t/how-can-i-get-on-server-an-uploaded-picture-using-ngcordova-from-ionic-app/18411/3 "2015-08-24T18:46:37Z")

</div>

I am also using express, is that module the only way of getting the image data?

---

<div class="post-metadata">

**Author:** ![luisito95](https://avatars.discourse-cdn.com/v4/letter/l/e47774/32.png) [@luisito95](https://forum.ionicframework.com/u/luisito95)\
**Post date:** [August 24, 2015, 7:08pm UTC](https://forum.ionicframework.com/t/how-can-i-get-on-server-an-uploaded-picture-using-ngcordova-from-ionic-app/18411/4 "2015-08-24T19:08:49Z")

</div>

Never mind for the dumb question after seconds of plugin in the module it was a success thanks !
