Recent

Custom Controls Using Angular Material

Git Repo:  https://github.com/yawahang/ohcontrols Features DatePicker (Date Picker, Time Picker, Date Time Picker, and many more) RatingPicker (Vertical, Horizontal, Custom Icons) Select (Single Select, MultiSelect, Single Column, MultiColumn) Recursive Treeview

Upload Profile Picture, Preview Image and image validation

var image = new Image();
var file;

function readImage(file) { //  function for image preview before upload

  var useBlob = false && window.URL;

  var reader = new FileReader();
  reader.addEventListener("load"function () {

    image.addEventListener("load"function () {

      var preview = $(".preview");
      preview.html(this);

      if (useBlobwindow.URL.revokeObjectURL(image.src);

    });

    image.style = "margin-left:auto;margin-right: auto;display:block;;max-height:400px;max-width:570px;";
    image.src = useBlob ? window.URL.createObjectURL(file) : reader.result;
    image.id = "upload_image_view";  // add image preview on image select    
  });

  reader.readAsDataURL(file);
  $('.upload').removeAttr('disabled');
}

//  Call image validation on file uploader change event
$(document).on("change"".file"function () {

  var input = $('.file');
  file = this.files[0];

  if (!file) {

    window.alert"File upload not supported by your browser.");
       } else {

  fileName = '';
  fileName = file.name.replace(/\\/g'/').replace(/.*\//'');

  // JPE|PNG|JPEG|JPG|GIF|BMP allowed
  if (/\.(jpe?g|png|gif|bmp)$/i.test(file.name)) {

    if ((Math.round(file.size / 1024 / 1024)) <= 1) {

      $('.form-control').val(fileName);
      readImage(file);

    } else {

      window.alert('Maximum (1 MB) of image size allowed.');
    }
  }
  else {

    window.alert('Only image file allowed.');
  }
}
   });

Comments

Top Posts

SQL Server Symmetric Key & Certificate based Encryption With AES_256 Algorithm

Kendo Grid Angular Column Width, minResizableWidth dynamic

Kendo Grid AutoFit Columns