Hello I would like to ask if how do you detect a File specifically Jpeg,PNG, and gif. If it is corrupted as I need to add it on my code below. I tried testing using a corrupted image but its not working. I have added aditional letters on the image using notepad++ for testing.
uploadImageChange(e){
const file = e.target.files[0];
const fileType = file.type;
this.uploadeImageFileType = fileType.replace('image/','');
this.showImageModalErrorMessage = false;
this.showUploadSuccessMessage = false;
this.hideUploadBTN = true;
let fileReader = new FileReader();
fileReader.readAsDataURL(file);
if(file.type == "image/png" || file.type == "image/jpeg" || file.type == "image/gif"){
if(file.size < 2097152){
this.imageSelectedUrl = URL.createObjectURL(file);
this.showImageSaveContent = true;
this.modalSecondInstruction = true;
this.hideUploadBTN = false;
// fileReader.onloadend = function(fileLoad){
// imageAssign();
// fileReader.abort();
// }
fileReader.onloadend = (e) => {
this.uploadImage64 = e.target.result.replace('data:'+fileType+';base64,','');
}
}else{
this.imageModalErrorMessage = this.dataInput.incorrectImageSizeErrorMsg
this.showImageModalErrorMessage = true;
this.hideUploadBTN = true;
}
}else{
this.imageModalErrorMessage = this.dataInput.incorrectImageFormatErrorMsg
this.showImageModalErrorMessage = true;
this.hideUploadBTN = true;
}
},