我最近为一个项目做了这个。您可以使用XHR在表单数据中发送图像:let formdata = new FormData();
formdata.append("image", data);
let xhr = new XMLHttpRequest();
xhr.open('POST', 'http://yourserver/image', true);
xhr.onload = function () {
if (this.status === 200)
console.log(this.response);
else
console.error(xhr);
};
xhr.send(formdata);
我在使用toDataURL转换画布时遇到问题,因此我使用toBlob来进行更简单的转换:
^{pr2}$
下面是一个嵌入JavaScript和Python服务器的示例HTML文件。在
HTML和嵌入式JavaScript
JavaScript使用:getUserMedia启动本地视频流
鼠标单击图像以启动图像捕获
从getUserMedia流保存图像的画布对象
XHR将文件作为表单数据发送
代码:
Post an Image test/* mirror the image */
video, canvas {
transform: scale(-1, 1); /*For Firefox (& IE) */
-webkit-transform: scale(-1, 1); /*for Chr