title: How to open image in javascript,sent by express.js sendfile function[+SOLUTION]
body: <p>I have a simple server which has this method</p>
  
  <pre><code>app.post('/', function (req, res) {
      res.sendfile(path.resolve(req.files.image.path));
  });
  </code></pre>
  
  <p>How do I get data, on client side in Image object?
  this is my ajax.success method,at least what i tried...</p>
  
  <pre><code>success: function (res) {
      console.log(res);
      var canvas = document.getElementById("mainCanvas");
      var ctx = canvas.getContext("2d");
      var img = new Image();
      img.onload = function () {
          ctx.drawImage(img,0,0);
      }
      img.src=res
  }
  </code></pre>
  
  <p>Really looking for answer already for 2 days... tried a lot of ways, but none worked. I am not even sure what I receive from server - is it bytes array?</p>
  
  <p><strong>SOLUTION:</strong>
  so, i figured out that post request does not need to send file back, Image.src sends its own get request to server</p>
  
  <pre><code>app.post('/', function (req, res) {
  res.send(path.basename(req.files.image.path));
  });
  /* serves all the static files */
  app.get(/^(.+)$/, function(req, res){ 
       console.log('static file request : ' + req.params);
       res.sendfile( __dirname + req.params[0]); 
  });
  </code></pre>
  
  <p>client:</p>
  
  <pre><code>success: function (res) {
                  var canvas = document.getElementById("mainCanvas");
                  var ctx = canvas.getContext("2d");
                  var img = new Image();
                  console.log(res);
                  img.onload = function () {
                      ctx.drawImage(img,0,0);
                  }
                  img.src="/uploads/"+res;
              }
  </code></pre>