I have this code (please see below) when the user is selecting an image
i'd like to display a preview of the image. It works well for standard formats
but since tiff is not supported by some of the browser it will show a broken image if
user is selecting a tiff image. I have no problem converting the image when i'm getting
it from the server my issue is on the client side.
The relevant javascript:
$(function () {
$(document).on('change', '#ImageData', function (evt) {
try {
var file = evt.target.files[0] || evt.srcElement.files[0];
}
catch (e) {
removeImg();
return;
}
if (isImage(file)) {
var reader = new FileReader();
reader.onloadend = (function () {
return function (event) {
var img = document.getElementById('img-id');
img.src = event.target.result;
};
})(file);
reader.readAsDataURL(file);
}
else {
removeImg();
}
});
});
The relevant html:
@Html.ValidationMessageFor(model => model.imageFile, "", new { @class = "text-danger" })
@Html.TextBoxFor(model => model.imageFile, new { type = "file", name = "imageFile", id = "ImageData" })
<img id='img-id' style="height: 300px; width: auto;">