1

I am using angular 1.7 with material design for my project. i am using angular material file input for this but it gives me result in file format. what i need is to convert that file format into base64 format. i have tried some external libraries but it doesn't work for me. can anyone post code or make a codepen/jsfiddle.

ZearaeZ
  • 899
  • 8
  • 20

1 Answers1

0

You can try this solution (this is o copy of this post: How to convert file to base64 in JavaScript? ):

function getBase64(file) {
   var reader = new FileReader();
   reader.readAsDataURL(file);
   reader.onload = function () {
     console.log(reader.result);
   };
   reader.onerror = function (error) {
     console.log('Error: ', error);
   };
}

var file = /*Your file goes here*/
getBase64(file); // prints the base64 string
Matthias Gwiozda
  • 505
  • 5
  • 14