I have simple input file which accepts only images. I want to show the success message on upload any images which is less than 2mb size. But when i choose the image and inspect element, the image is converting to base64 format and size of the base64 sting is exceeding (4/3 ratio) the actual size of the image.
My question is
1. how to keep the size same as the actual image.?
2. Is there any other way to fix it.
My code is:
<input type="file" onchange="uploadImage(event)" />
jQuery
function uploadImage(event){
var fileReader = new FileReader();
if (fileReader && fileList && fileList.length) {
$scope.fileSize = fileList[0].size;
fileReader.readAsDataURL(fileList[0]);
var ext = fileList1.value.match(/\.([^\.]+)$/)[1].toLowerCase();
switch (ext) {
case 'jpg':
case 'bmp':
case 'png':
case 'tif':
case 'jpeg':
$scope.hasInvalidFiles = false;
fileReader.onload = function (event) {
var imageData = event.target.result;
console.log(imageData);
}
if (fileList[0].size < 2000) {
console.log("success");
}
else {
console.log("Failure");
}
break;
default:
console.log("Invalid");
}
}
}