Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

image base64 to file javascript

 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});
    }
    
    //Usage example:
    var file = dataURLtoFile('data:text/plain;base64,aGVsbG8gd29ybGQ=','hello.txt');
    console.log(file);
Comment

PREVIOUS NEXT
Code Example
Javascript :: How to make the width of a react native element adjust according to the contents 
Javascript :: how to delete a folder in node js 
Javascript :: how to get array from items quantity 
Javascript :: ajax get with parameters 
Javascript :: FileReader get filename 
Javascript :: javascript use camera 
Javascript :: javascript array of zeros of n length 
Javascript :: `object` ("[object Object]") cannot be serialized as JSON. Please only return JSON serializable data types 
Javascript :: ascending and descending val in array using js 
Javascript :: js delete object in dict 
Javascript :: remove element from an array 
Javascript :: localstorage javascript 
Javascript :: how to redirect to another page in javascript on submit type 
Javascript :: sleep js 
Javascript :: how to cut a string in js 
Javascript :: React’ must be in scope when using JSX react/react-in-jsx-scope 
Javascript :: clean react app 
Javascript :: s3.getobject nodejs example async await 
Javascript :: js find first line break in string 
Javascript :: angular cli path environment variable 
Javascript :: react native callback function uses default state value 
Javascript :: jquery remove element 
Javascript :: react image compression 
Javascript :: convert timestamp to date javascript 
Javascript :: sum row values in datatable jquery 
Javascript :: angular call function every x seconds 
Javascript :: discord js convert timestamp to date 
Javascript :: remove all white space from text javascript 
Javascript :: set cursor type javascript 
Javascript :: node eventemitter emit error 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =