I have this function on a React component
handleChangeImage: function (evt) {
console.log("Uploading");
var self = this;
var reader = new FileReader();
var file = evt.target.files[0];
reader.onload = function(upload) {
self.setState({
image: upload.target.result
});
};
reader.readAsDataURL(file);
console.log(this.state.image);
console.log("Uploaded");
},
and is called here
<input ref="file" type="file" name="file"
className="upload-file"
id="file"
onChange={this.handleChangeImage}
encType="multipart/form-data"
required/>
I'm trying to get the base64 string to send via AJAX to a server running Flask. The problem is everytime I select a file, it is logged as null in the console
Funny thing is, if I try to select the file a second time it now logs the whole string. I must be missing something simple...