方法封装
export default function base64ToBlob(base64Data) {
var byteString
if (base64Data.split(',')[0].indexOf('base64') >= 0) {
byteString = atob(base64Data.split(',')[1])
} else {
byteString = unescape(base64Data.split(',')[1])
}
var mimeString = base64Data.split(',')[0].split(':')[1].split(';')[0]
var ia = new Uint8Array(byteString.length)
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i)
}
return new Blob([ia], {
type: mimeString
});
}
方法使用
let signImg = base64ToBlob(img);
let formData = new FormData();
formData.append("file", signImg);
使用实例
vue base64图片上传到腾讯云cos