I want to read a file input as a binary string. Therefore I have written a binary string reader (following this post), but I get the error message:
Unhandled Rejection (TypeError): Failed to execute 'readAsBinaryString' on 'FileReader': parameter 1 is not of type 'Blob'.
Reader:
ReadAudioasBinaryString(e) {
const audio = e.target.files[0];
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (event) => {
resolve(event.target.result);
};
reader.onerror = (err) => {
reject(err);
};
reader.readAsBinaryString(audio);
}, console.log (audio));
}
Input
<div className="form-group">
<label>Audio</label>
<input
className="form-control"
type="file"
name="audio"
onChange={this.ReadAudioasBinaryString}
ref={this.inputRef} //
/>
</div>
Happy for every hint!
const audio = e.target.files[0];or something like that? And if that works, your resolving result is currently discarded. What is the end goal? What's supposed to happen with the audio file selected by the user?ReadAudioasBinaryStringis supposed to do. See also this post link.name?) Anyway, you can ditch the Promise wrapper, just usethis.setState({ binaryString: event.target.result })in theonload.const audio = e.target.files[0];(see also the updated post). Unfortently The error messages stays the same.