title: Get download url of Uploaded image in Sails.JS
body: <p>I am working on an Api in Sails.js where I need to upload image to server through api and get url of that uploaded image for later use from Mobile App. For doing this, my upload codes are as follows</p>
  
  <pre><code>upload: function  (req, res) {
  
      var uploadPath = '../../assets/images' ;
      req.file('avatar').upload({ dirname: uploadPath },function onUploadComplete (err, files) {
  
          if (err) {
              return res.serverError(err);
          } else {
              var image = files[0];
              var fd = image.fd ;
              var index = fd.lastIndexOf('/');
              var imageName = fd.substring(index+1 , fd.length);
              return res.json({ image : '/images/' + imageName });
          }
      });
  }
  </code></pre>
  
  <p>This gives me result like the following one...</p>
  
  <pre><code>{
      "image": "/images/bc4f03ec-0d9c-4553-b59a-9ddec427a265.jpg"
  }
  </code></pre>
  
  <p>If I append the path with my localhost like this </p>
  
  <pre><code>http://localhost:1337/images/bc4f03ec-0d9c-4553-b59a-9ddec427a265.jpg
  </code></pre>
  
  <p>it works and image is loading in the browser. But when I deploy my application to production server, it's not working and giving me 404 error.</p>
  
  <p>To solve this problem, I have already written another get action like this </p>
  
  <pre><code>download: function (req, res) {
      res.sendfile(req.path.substr(1));
  },
  </code></pre>
  
  <p>where /routes entry is</p>
  
  <pre><code> 'get /images/*' : {
          controller : 'FileController',
          action : 'download'
      }
  </code></pre>
  
  <p>But that didn't help, I am getting 404 at localhost.</p>
  
  <p>Can anyone suggest me how can I solve this problem ? </p>