video . set attribute(' Cross origin ',' anonymous ')//跨域處理
var canvas = window . canvas = document . createelement(" canvas ");
畫布.寬度= 500;
canvas.height = 300
canvas.getContext('2d ')。drawImage(視頻,0,0,500,500);?//在畫布上渲染當前視頻圖片,圖片大小與視頻分辨率壹致。
var images = canvas . toda taurl(" image/png ");//canvas的api中的toDataURL()保存圖片[toda taurl](/zh-cn/docs/web/API/htmlcanvaselement/toda taurl)。
var arr = images.split(','),
mime = arr[0]。匹配(/:(。*?);/)[1],
bstr = atob(arr[1]),
n = bstr .長度,
u8arr = new uint 8 array(n);
while (n - ) {
u8arr[n]= bstr . charcodeat(n);
}
var文件=?新建文件([u8arr],' cutout.jpg ',{ type:mime });
let config = { headers:{ ' Content-Type ':' multipart/form-data ' } }
let formData = new formData();
formData.append('multipart ',file,file . name);
axios . post(' http://127 . 0 . 0 . 1:8080/API/v 1/工作單/操作/上傳',formData,config)
。然後(res = & gt{})