FileReader错误:对象已经忙于读取Blob [英] FileReader error: The object is already busy reading Blobs

查看:3476
本文介绍了FileReader错误:对象已经忙于读取Blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为照片库上传制作拖放式文件上传系统。这是我处理丢弃文件的源代码。这个可以工作多个文件,如果我逐个删除它可以工作,但是当我同时丢弃多个文件时出现此错误:

I'm making a drag-and-drop file upload system for photo gallery uploads. This is my source code handling dropped files. This one works multiple files if I drop them one by one it works but when I drop more than one at the same time this error occures:

未捕获的InvalidStateError:无法在'FileReader'上执行'readAsDataURL':对象已经忙于读取Blob。

function handleFiles(files)
{
    var reader = new FileReader();
    var formdata = new FormData();

    $.each(files, function(i, j)
    {
        $("td.photos span.status").html("Processing file: "+j.name);

        formdata.append('file', j);

        $.ajax({
            url: "uploadalbum.php",
            type: "POST",
            dataType: "json",
            data: formdata,
            processData: false,
            contentType: false,
            success: uploadfinished
        });

        reader.onload = handleReaderLoad;
        reader.readAsDataURL(j);
    });
}

任何想法?

推荐答案

我认为错误已经给你。



无法在'FileReader'上执行'readAsDataURL':对象已经忙于读取Blob

Failed to execute 'readAsDataURL' on 'FileReader': The object is already busy reading Blobs


所以文件阅读器已经很忙但只有当你删除多个文件时?然后它可能忙于第一个文件(和第二个崩溃)。

So the file reader is already busy but only when you drop multiple files? Then it is probably busy with the first file (and the second crashes).

当你输入 var reader = new FileReader(); 在你的jQuery每个循环中它将如下所示:

When you put var reader = new FileReader(); in your jQuery each loop it will work like below:

$.each(files, function(i, j)
{
    var reader = new FileReader();
    $("td.photos span.status").html("Processing file: "+j.name);

    formdata.append('file', j);
    .... <snip>

}

这篇关于FileReader错误:对象已经忙于读取Blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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