JSFiddle - React, Tailwind, and code Playground
HTML
<input type="file" id="fileinput" />
<select id='encoding'>
<option value='windows-1251'> Windows-1251 </option>
<option value='windows-1252'> Windows-1252 </option>
</select>
JavaScript
function readSingleFile(evt) {
//Retrieve the first (and only!) File from the FileList object
var f = evt.target.files[0];
if (f) {
var r = new FileReader();
r.onload = function(e) {
var contents = e.target.result;
alert( "Got the file.n"
+"name: " + f.name + "\n"
+"type: " + f.type + "\n"
+"size: " + f.size + " bytesn"
+ "starts with: " + contents.substr(1, contents.indexOf("\n"))
);
}
var encoding = document.getElementById('encoding').value;
r.readAsText(f, encoding);
} else {
alert("Failed to load file");
}
}
document.getElementById('fileinput').addEventListener('change', readSingleFile, false);