Convert Jpg File to Base64 after HttpRequest


#1

Hi,
So I’m trying to get my imagefile of my serve to use it in my app.
the Imagefiles are stored as .jpg files but to use it i need them in a base64String

HTTP.get('ServerAdress', {}, {})
  .then( response => {  let str = response.data; }

this is what i have so far i’ve tried to convert it with filereader:

let fileReader = new FileReader();

    fileReader.onload = function (event) {
      var srcData = event.target.result; // <--- data: base64

      var newImage = document.createElement('img');
      newImage.src = srcData;

      document.getElementById("imgTest").innerHTML = newImage.outerHTML;
      alert("Converted Base64 version is "+document.getElementById("imgTest").innerHTML);
      alert("Converted Base64 version is "+document.getElementById("imgTest").innerHTML);

    }
    alert(encodeURIComponent(str));

but the line event.target.result doesn’t work
is there a better or nicer solution??