Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. export default dataURI => {
  2. // convert base64/URLEncoded data component to raw binary data held in a string
  3. let byteString;
  4. if (dataURI.split(',')[0].indexOf('base64') >= 0)
  5. byteString = atob(dataURI.split(',')[1]);
  6. else byteString = unescape(dataURI.split(',')[1]);
  7.  
  8. // separate out the mime component
  9. let mimeString = dataURI
  10. .split(',')[0]
  11. .split(':')[1]
  12. .split('')[0];
  13.  
  14. // write the bytes of the string to a typed array
  15. let ia = new Uint8Array(byteString.length);
  16. for (let i = 0; i < byteString.length; i++) {
  17. ia[i] = byteString.charCodeAt(i);
  18. }
  19.  
  20. return new Blob([ia], { type: mimeString });
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement