In my Angular application, I have implemented a method that verifies the size and dimensions of an image file and returns either false or true based on the validation result. Below is the code snippet for this function:
checkFileValidity(file: any, multiple: boolean): any {
const reader = new FileReader();
const img = new Image();
img.src = window.URL.createObjectURL(file);
reader.readAsDataURL(file);
return img.onload = function () {
const tableError = []
const width = img.width;
const height = img.height;
console.log(img.width);
console.log(img.height);
if (file.size > 3000000) {
console.log('size');
tableError.push('size');
}
if (width < 1919 || height < 1079) {
console.log('dimension');
tableError.push('dimension');
}
if (tableError.length > 0 && !multiple) {
return false;
} else if (tableError.length > 0) {
console.log('size+dimension');
return false;
}
return true;
}()
}
I encountered an error at the line "return img.onload = function () {". How can I resolve this issue?