I
I
Ilya Magdenko2018-03-27 04:41:57
Canvas
Ilya Magdenko, 2018-03-27 04:41:57

How to send an image to the server?

Maybe the question is super stupid, but I still do not understand.
Look, I'm running the index.js server.
Next, I have a path to the page (I use the template engine and express)

app.get('/camera', function(req, res) {
  res.render('camera');
});

On the page, I create a photo from the camera in canvas
<div class="app">
          <video id="camera-stream"></video>
            <img id="snap">
            <p id="error-message"></p>
            <div class="controls">
              <a href="#" id="take-photo" title="Take Photo"><i class="material-icons">camera_alt</i></a>
            </div>
            <canvas id="simple_sketch"></canvas>
          </div>

in the my.js file I take pictures every 5 seconds.
function takeSnapshot(){
  var hidden_canvas = document.querySelector('canvas'),
      context = hidden_canvas.getContext('2d');

  var width = video.videoWidth,
      height = video.videoHeight;

  if (width && height) {
    hidden_canvas.width = width;
    hidden_canvas.height = height;

    context.drawImage(video, 0, 0, width, height);

    return hidden_canvas.toDataURL('image/png');
  }
}

How do I send them back to index.js ? I am uploading a picture to the hosting server through a variable. How do I load everything that the my.js file does? Here is a piece from index.js:
var cloudinary = require('cloudinary');
var image = "Сюда нужно кидать фотки каждые 5 секунд";
cloudinary.uploader.upload(image, function(result) {
  console.log(result)
});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question