title: How to get byte array from a file in reactJS
body: <p>I've got a form for uploading Avatar image and I have to send the image file in the format of binary string; so far I've tried <code>ReadAsBinaryString</code> from <code>FileReader</code> but it's not working:(
  here's my code:</p>
  
  <pre><code>&lt;form onSubmit={this.onFormSubmit}&gt;
        &lt;div className="row justify-content-center mb-2"&gt;
             &lt;input type="file" id="avatar"  accept="image/png, image/jpeg" 
              onChange={this.uploadedImage} /&gt;
             &lt;button type="submit" className="btn btn-sm btn-info"&gt;Send&lt;/button&gt;
         &lt;/div&gt;
    &lt;/form&gt;
  </code></pre>
  
  <p>and that is how I'm trying to use <code>ReadAsBinaryString</code> in <code>uploadedImage</code> function:</p>
  
  <pre><code>uploadedImage(e) {
      let reader = new FileReader();
      let file = e.target.files[0];
      console.log(file); //I can see the file's info
      reader.onload= () =&gt; {
          var array = new Uint32Array(file);
          console.log("_+_array:",array); // the array is empty!
          var binaryString = String.fromCharCode.apply(null,array) ;
          console.log("__binaryString:",binaryString);
        this.setState({
          file: binaryString
        },()=&gt;{
          console.log(this.state.file);//ergo file is set to an empty image
      });
      }
      reader.readAsArrayBuffer(file)
  }
  </code></pre>
  
  <p>so to sum it up, I get a file but I can't convert it to byte array; Is there anything wrong with this code or this approach is completely wrong?</p>