I am trying to figure out a way to basically setState for the fileName and contents of the file when the user selects the file. Or if not setState, call another method as shown below
performFileUpload() {
var tempFileName: string;
let input = document.createElement('input');
input.type = 'file';
input.accept = '.xml';
input.addEventListener("change", function() {
const file = this.files[0];
tempFileName = this.files[0].name;
var reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onerror = reject;
reader.onload = function (evt) {
let result = evt.target.result.toString();
//TODO: Have a way to setState({fileName:tempFileName, selectedFile: result})
//Or simply call postNewFile(tempFileName, result);
};
input.click();
})
}
postNewFile(nameOfJrfl: string, selectedJrfl: string) { //Send a post }