This question have lots of answers on JQuery and JavaScript. And also some versions of Angular.
I tried lots of solutions but none of them work out.
I'm using Angular 7 and trying to validate the Width and Height of the Image Uploaded by the user.
Here's my .html code snippet:
<input type="file" name="upload" id="androidPhoneFile" class="upload-box" placeholder="Upload File" multiple="multiple" (change)="onAndroidPhoneChange($event)" formControlName="androidPhone" #androidPhonePhoto>
And here's my .ts component file:
AddFilesToFormData(event: any, fileName: string) {
const reader = new FileReader();
const img = new Image();
img.onload = function() {
const height = img.height;
const width = img.width;
console.log('Width and Height', width, height);
};
img.src = event.target.files[0];
if (event.target.files && event.target.files.length) {
const [file] = event.target.files;
reader.readAsDataURL(file);
reader.onload = () => {
for (let i = 0; i < event.target.files.length; i++) {
this.formData.append(fileName, event.target.files[i]);
this.numberOfPhotos++;
}
};
}}