1 function dataURLtoFile(dataurl, filename) {
2
3 var arr = dataurl.split(','),
4 mime = arr[0].match(/:(.*?);/)[1],
5 bstr = atob(arr[1]),
6 n = bstr.length,
7 u8arr = new Uint8Array(n);
8
9 while(n--){
10 u8arr[n] = bstr.charCodeAt(n);
11 }
12
13 return new File([u8arr], filename, {type:mime});
14 }
15
16 //Usage example:
17 var file = dataURLtoFile('data:text/plain;base64,aGVsbG8gd29ybGQ=','hello.txt');
18 console.log(file);