Last active
          February 18, 2021 20:02 
        
      - 
      
 - 
        
Save HaNdTriX/bdffd11761701fbeba27f23e9a69515f to your computer and use it in GitHub Desktop.  
    Example of converting a file to a dataURL in ES6
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | const toDataURL = url => fetch(url) | |
| .then(response => response.blob()) | |
| .then(blob => new Promise((resolve, reject) => { | |
| const reader = new FileReader() | |
| reader.onloadend = () => resolve(reader.result) | |
| reader.onerror = reject | |
| reader.readAsDataURL(blob) | |
| })) | 
fetch has not so good support and is experimental
line 8, I think you make a typo.
change to like this
  }));
    @rohmanhm yes!!!
awesome!
@rohmanhm I have updated the gist. Totally missed that 😳
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Usage
Works not only for images 😄
more info