file对象和base64互转工具类
base64转file对象
参数一:base64内容
参数二:生成的file文件名称
//base64转file对象
export function dataURLtoFile(dataurl, filename) {
var arr = dataurl.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new File([u8arr], filename, { type: mime });
}
base64转bolb对象
参数一:base64内容
//base64转bolb对象
export function dataURLtoBlob(dataurl) {
var arr = dataurl.split(','),
mime = arr[0].match(/:(.*?);/)[1],
bstr = atob(arr[1]),
n = bstr.length,
u8arr = new Uint8Array(n);
while (n--) {
u8arr[n] = bstr.charCodeAt(n);
}
return new Blob([u8arr], { type: mime });
}
bolb对象转file对象
参数一:blob对象
参数二:生成的file文件名称
//bolb对象转file对象
export function blobToFile(theBlob, fileName){
theBlob.lastModifiedDate = new Date();
theBlob.name = fileName;
return theBlob;
}
版权声明:本文为qq_41547661原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。