uploading file Properties

Checking Uploading file Info:-

To check uploading file properties and preview it, I am using a file controller and call below function onchange.

var fileInput = document.querySelector('#logo'),
    file = fileInput.files[0],
    preview = document.querySelector("#logoImage"),
    r = new FileReader();

if (file.type == "image/jpeg" || file.type == "image/jpg") {
    r.onload = function(e) {
        preview.src = r.result;
        preview.style.display = "block";
    return true;

alert("please select valid file");
fileInput.value = "";
return false;

Here first we are testing for the uploading file extension if its jpg/jpeg we will continue to fetch its content and set source to image. Otherwise we will create alert to upload a valid file.

Leave a Reply

Your email address will not be published. Required fields are marked *