FileReader onload not getting fired when selecting same file in Chrome

白昼怎懂夜的黑 提交于 2021-02-08 20:00:07

问题


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.


回答1:


Check this questions that are similar to your problem:

Chrome file upload bug: on change event won't be executed twice with the same file

input file onchange event not being fired in chrome



来源:https://stackoverflow.com/questions/34534358/filereader-onload-not-getting-fired-when-selecting-same-file-in-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!