title: how to convert file input to base64 - react js
body: <p>I have a file input and I want to convert it to base64 and send to server side. this is my code:</p>
  
  <pre><code>var avatar = (this.refs.avatar) ? this.refs.avatar.files : "" ;
  
  if(avatar.length &gt; 0){
    avatar = avatar[0]
    let fileReader = new FileReader();
    let file = null;
    fileReader.onload = function(fileLoadedEvent) {
         file = fileLoadedEvent.target.result;
  
     };
     fileReader.readAsDataURL(avatar);
  }else{
    avatar = ""
  }
  
  console.log(avatar); //File(2468670) {name: "wood.png", lastModified: 1524227213060, lastModifiedDate: Fri Apr 20 2018 16:56:53 GMT+0430 (+0430), webkitRelativePath: "", size: 2468670, …}
  </code></pre>
  
  <p>should I covert <code>avatar</code> to base64? 
  I should convert to origin file on server side.</p>