0

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. Corrupted Image using Notepad++

 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;
  }
},
pine ching
  • 15
  • 6
  • so you need to check on the client side before sending to the server? If this were to be done outside the browser, how would **you** detect a *corrupted* image in a program that isn't a browser? – Jaromanda X Jan 20 '20 at 03:33
  • Maybe a solution would be to try to draw this image on a canvas et check for error. I did not try it, but that should work pretty well I guess. – Scalpweb Jan 20 '20 at 03:34
  • @JaromandaX this is on browser – pine ching Jan 20 '20 at 03:53
  • yes, I know it is on the browser - I'm asking if **you** know how to detect, in any program, a **corrupt** image – Jaromanda X Jan 20 '20 at 03:56
  • *I tried testing using a corrupted image but its not working* - what isn't working? do you have code that detects a corrupt image? is that not detecting a corrupt image? – Jaromanda X Jan 20 '20 at 04:02
  • @JaromandaX what i mean it is continuing to upload the image and i also tried to check the file on watch if i can see any different from a not corrupted image but they are the same. properties like format and size – pine ching Jan 20 '20 at 04:59
  • @Scalpweb working now thanks – pine ching Jan 20 '20 at 05:25
  • @JaromandaX Its working now i added code from this https://stackoverflow.com/questions/41462108/js-check-if-an-image-truncated-corrupted-data – pine ching Jan 20 '20 at 05:25

0 Answers0