JSFiddle - React, Tailwind, and code Playground
HTML
<input onchange="userPreviewImage(this)" type="file" accept="image/*" />
JavaScript
window.onload = function () {
this.userPreviewImage = function (fileInput) {
var files = fileInput.files;
var file = files[0];
var reader = new FileReader();
reader.onload = function (aImg) {
$.post("/echo/html/", {
html: aImg.target.result
})
.then(function (data, textStatus, jqxhr) {
console.log(data, textStatus);
}, function(jqxhr, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
})
};
reader.readAsDataURL(file);
}
}