2024-08-20 12:11:31 +00:00
|
|
|
|
/**
|
|
|
|
|
* database64文件格式转换为2进制
|
|
|
|
|
*
|
|
|
|
|
* @param {[String]} data dataURL 的格式为 “data:image/png;base64,****”,逗号之前都是一些说明性的文字,我们只需要逗号之后的就行了
|
|
|
|
|
* @param {[String]} mime [description]
|
|
|
|
|
* @return {[blob]} [description]
|
|
|
|
|
*/
|
2024-08-21 01:17:14 +00:00
|
|
|
|
export default function (data, mime) {
|
|
|
|
|
data = data.split(',')[1]
|
|
|
|
|
data = window.atob(data)
|
|
|
|
|
const ia = new Uint8Array(data.length)
|
2024-08-20 12:11:31 +00:00
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
2024-08-21 01:17:14 +00:00
|
|
|
|
ia[i] = data.charCodeAt(i)
|
|
|
|
|
}
|
2024-08-20 12:11:31 +00:00
|
|
|
|
// canvas.toDataURL 返回的默认格式就是 image/png
|
|
|
|
|
return new Blob([ia], {
|
|
|
|
|
type: mime
|
2024-08-21 01:17:14 +00:00
|
|
|
|
})
|
|
|
|
|
}
|