S3 file upload file object using node js
<p>I'm using Sailsjs 0.12.1, node.js 4.2.6</p>

<p>I want to upload the file From front-end(angular.js) through an API and from backend I want to upload the file to the AWS S3 bucket.</p>

<p>front-end I'm sending the file to the api. In backend I'm getting the file with the name but while uploading the file to S3 I'm getting the error  </p>

<blockquote>
  <p>Cannot determine length of [object Object]</p>
</blockquote>

<p>I google the error and found the many links but my bad luck.</p>

<p>Back-end</p>

<pre><code> uploadPersonAvtar: function(req, res) {
    var zlib = require('zlib');
    var file = req.file('image');
    var mime = require('mime');

    data = {
        Bucket: 'bucket',
        Key : 'my_key',
        Key: file.name,
        Body: file,
        ContentType: mime.lookup(file.name)
      };

    // Upload the stream
    var s3obj = new AWS.S3(S3options);
    s3obj.upload(data, function(err, data) {
        if (err) console.log("An error occurred", err);
        console.log("Uploaded the file at", data);
    })
}
</code></pre>

<blockquote>
  <p>Is my approach is correct</p>
  
  <p>If yes what I'm doing wrong. </p>
</blockquote>

<p>I want to know how to use the file object to upload the file.<br>
I can create a read stream but I don't have the file path When I'm creating the file object I'm getting the error: path must be a string </p>