【发布时间】:2019-11-28 07:48:05
【问题描述】:
我想将在画布中捕获的照片从浏览器中的 javascript 上传到 nodejs 服务器。我没有得到正确的方法。请帮忙。非常感谢。
(function(){
var video=document.getElementById('video'),
canvas = document.getElementById('canvas'),
vendorUrl = window.URL || window.webkitURL;
context = canvas.getContext('2d');
//photo = document.getElementById('photo');
navigator.getMedia = navigator.getUserMedia ||
navigator.webkitGetUserMedia ||
navigator.mozGetUserMedia ||
navigator.msGetUserMedia;
navigator.getMedia({
video: true,
audio: false
}, function(stream){
video.srcObject=stream;
video.play();
}, function(error){
});
document.getElementById('capture').addEventListener('click',function(){
context.drawImage(video,0,0,400,300);
// photo.setAttribute('src',canvas.toDataURL('image/png'));
download();
});
})();
function download() {
var download = document.getElementById("capture");
var image = document.getElementById("canvas").toDataURL("image/png")
.replace("image/png", "image/octet-stream");
download.setAttribute("href", image);
//download.setAttribute("download","archive.png");
}
此代码可以正常下载捕获的图像,但我无法将相同的图像上传到节点服务器。
【问题讨论】:
-
@rebecca 有点不同,Sneha 想从画布中获取数据,然后发送该数据(我认为没有上传按钮)
标签: javascript node.js npm