You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
369 B
18 lines
369 B
1 year ago
|
/**
|
||
|
* dataurl: base64
|
||
|
* filename: 设置文件名称
|
||
|
*/
|
||
|
export const dataURLtoFile = (dataurl, filename) => {
|
||
|
let 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
|
||
|
});
|
||
|
}
|