我有一个div,并使用canvas拍摄了该div的快照并将画布图像存储在变量getcanvas中,现在我想使用节点将该画布图像存储到mysqldatabase
答案 0 :(得分:0)
两种方式
/* send */
const dataUrl = canvas.toDataURL()
// TODO: post dataUrl to server and save it to mysql
/* get */
// get dataUrl from server
const img = document.createElement('img');
// attach dataUrl to img.src to show it
img.src = dataUrl
/* send */
const dataUrl = canvas.toDataURL()
const [memeStr, dataStr] = (dataUrl || '').split(',')
const mime = memeStr
.split(',')[0]
.split(':')[1]
.split(';')[0]
const bstr = atob(dataStr)
const u8arr = new Uint8Array(bstr.length)
for (let i = 0; i < bstr.length; i++) {
u8arr[i] = bstr.charCodeAt(i)
}
const imageFile = new Blob([u8arr], { type: mime })
// TODO: you got the image file (by default is a png file)
// send it to the server and store its path in mysql
/* get */
// get imagePath from server
const img = document.createElement('img');
// attach imagePath to img.src to show it
img.src = imagePath