【问题标题】:How to store a captured image into MySQL database using JavaScript and Node.js如何使用 JavaScript 和 Node.js 将捕获的图像存储到 MySQL 数据库中
【发布时间】:2012-10-07 14:44:36
【问题描述】:

我正在使用画布捕获图像,我想使用 Javascript 将捕获的图像存储在 MySQL 数据库中。

这是我的代码:

<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>

【问题讨论】:

  • 您需要以某种方式将图像数据发送到服务器。我不知道我怎么可能……
  • 直接通过JS访问数据库比较困难,可以尝试通过ActiveX访问ODBC-数据库(支持mysql)。更多信息,请点击ODBC
  • 我在服务器端使用 node.js。如何将此图像发送到服务器端。
  • 如果您使用的是 node.js ...这篇文章可能会对您有所帮助 [链接]:stackoverflow.com/questions/5149545/…

标签: javascript html mysql node.js


【解决方案1】:

获取画布“屏幕截图”,将其编码为 BASE64 字符串,将其发送到 servlet/php/etc 并将其存储在 mysql 中应该可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-31
    • 2014-08-07
    • 2015-01-01
    • 2012-06-08
    • 1970-01-01
    • 2018-02-16
    • 2016-07-28
    • 1970-01-01
    相关资源
    最近更新 更多