4

I am capturing image using canvas and i want to store a captured image in MySQL Database using Javascript.

This is my code:

<html>  
      <head>
            <meta charset="utf-8">
            <meta name="viewport" content="width=device-width, maximum-scale=1.0">
            <style>
                body {width: 100%;}
                canvas {display: none;}
            </style>
            <title>Instant Camera - Remote</title>
            <script>

                var video, canvas, msg;
                var load = function () {
                    video  = document.getElementById('video');
                    canvas = document.getElementById('canvas');
                    msg    = document.getElementById('error');
                    if( navigator.getUserMedia ) {
                        video.onclick = function () {
                            var context = canvas.getContext("2d");
                            context.drawImage(video, 0, 0, 240, 320);
                            var image1 = canvas.toDataURL("image/png");
                    document.write('<img src="' + image1 + '" />');         
                        };

                    } else {
                        msg.innerHTML = "Native web camera not supported :(";
                    }
                };

                window.addEventListener('DOMContentLoaded', load, false);
            </script>
        </head>
        <body>
            <video  id="video" width="240" height="320" autoplay> </video>
            <p      id="error">Click on the video to send a snapshot to the receiving screen</p>
            <canvas id="canvas" width="240" height="320"> </canvas>
        </body>
        </html>
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
R J.
  • 1,522
  • 10
  • 25
  • 40
  • You need to send the image data to server somehow. I don't know how that i possible… – feeela Oct 17 '12 at 10:54
  • it is difficult to access database directly via JS.You could try to access ODBC-database(mysql supported) by ActiveX. For more info, click [ODBC](http://www.mysql.com/downloads/connector/odbc). – zetsin Oct 17 '12 at 10:55
  • I am using node.js for server side.How to send this image to server side. – R J. Oct 17 '12 at 11:33
  • 1
    If you are using node.js ... this post might help you [link] : http://stackoverflow.com/questions/5149545/uploading-images-using-nodejs-express-and-mongo – phucat Oct 17 '12 at 11:38

1 Answers1

2

getting a canvas "screenshot", encoding it into a BASE64 string, sending it to a servlet/php/etc and storing it in mysql should work.

flatline
  • 86
  • 2