在Chrome中选择相同文件时,不会触发FileReader onload [英] FileReader onload not getting fired when selecting same file in Chrome

查看:110
本文介绍了在Chrome中选择相同文件时,不会触发FileReader onload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

FileReader onload 不会第二次被触发,而FireFox一直都在触发该文件.

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. 用户选择相同的图像而没有任何更改.

  1. User selects same image without any change.

这一次用户应该再次收到验证消息.

This time user should get validation message again.

用户编辑了图片并更改了大小,然后再次上传.

User edited the image and changed size, uploaded again.

重新获得的文件值未更改,因此未调用上载或验证.

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

推荐答案

请检查与您的问题类似的问题:

Check this questions that are similar to your problem:

Chrome文件上传错误:更改事件不会对同一文件执行两次

未在chrome中触发输入文件onchange事件

这篇关于在Chrome中选择相同文件时,不会触发FileReader onload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆