我在输入文本框中上传文件时收到此错误。
未捕获DOMException:无法在'FileReader'上执行'readAsDataURL':对象已在忙于读取Blob。
我必须上传html文件并预览该文件中的文本,但在上传时会在控制台中抛出此错误。如何解决此错误。 这是我的javascript代码 -
> $(".image-preview-input input:file").change(function (){
> var file = this.files[0];
> var reader = new FileReader();
> var FileExtension = file.name.split('.')[file.name.split('.').length - 1].toLowerCase();
> if(FileExtension !== 'html'){
> $('#ValidationMessage').css("color", "red");
> $('#ValidationMessage').html("Please select the html extension file.");
> this.set('template','');
> $('.image-preview-input input:file').val("");
> }
> // Set preview image into the popover data-content
> reader.readAsText(file);
> reader.onload = function (e) {
> $('#ValidationMessage').empty();
> $(".image-preview-input-title").text("Change");
> $(".image-preview-clear").show();
> $(".image-preview-filename").val(file.name);
> self.set('template',e.target.result);
> }
> reader.readAsDataURL(file);
> });
答案 0 :(得分:0)
您正在阅读两次文件。
首先来到这里:
reader.readAsDataURL(file);
然后在这里:
onload()
我没有看到第二次阅读的原因。如果您打算使用它,请将其放在function tick() {
link.attr("d", function(d) {
var x1 = d.source.x,
y1 = d.source.y,
x2 = d.target.x,
y2 = d.target.y,
dx = x2 - x1,
dy = y2 - y1,
dr = Math.sqrt(dx * dx + dy * dy),
// z uzla do ineho uzla
drx = dr,
dry = dr,
xRotation = 0,
largeArc = 0,
sweep = 1;
//do sameho seba
if ( x1 === x2 && y1 === y2 ) {
xRotation = -45;
largeArc = 1;
drx = 30;
dry = 30;
x2 = x2 + 1;
y2 = y2 + 1;
}
return "M" + x1 + "," + y1 + "A" + drx + "," + dry + " " + xRotation + "," + largeArc + "," + sweep + " " + x2 + "," + y2;
});
}
回调中;