Anshad Vattapoyil
Anshad Vattapoyil

Reputation: 23483

FileReader onload not getting fired when selecting same file in Chrome

FileReader onload not getting fired on second time when the same file selected with Chrome, it's getting fired all the time for FireFox.

function uploadCover(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();
        reader.onload = function(e) {

            var image = new Image();
            image.src = e.target.result;

            image.onload = function () {
               // code
            };
        };
        reader.readAsDataURL(input.files[0]);
    }
}

Here I want to validate image width and height on upload. So there is two scenarios which is ending up with issue:

  1. User selects same image without any change.

    This time user should get validation message again.

  2. User edited the image and changed size, uploaded again.

    Again file value not changed, so the upload or validation not getting called.

Upvotes: 5

Views: 6410

Answers (1)

Related Questions