简体   繁体   English

Angular.js:未捕获的TypeError:无法在“ FileReader”上执行“ readAsDataURL”:参数1的类型不是“ Blob”

[英]Angularjs : Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'

I need to upload multiple images in a div , i try the below 我需要在div中上传多个图像,请尝试以下操作

angular code : 角度代码:

        $scope.stepsModel = [];
        $scope.imageUpload = function(element){
          var reader = new FileReader();
          reader.onload = $scope.imageIsLoaded;
          reader.readAsDataURL(element.files);
        }

        $scope.imageIsLoaded = function(e){
           $scope.$apply(function() {
            $scope.stepsModel.push(e.target.result);
           });
        }

html code : html代码:

    <input type="file" ng-model-instant  name="myImage" accept="image/*" onchange="angular.element(this).scope().imageUpload(event)"/>

I got this error : 我收到此错误:

Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob'.
at b.$scope.imageUpload (new_ads.js:34)
at HTMLInputElement.onchange (new_ads:202)

I saw some links here ,that all for single image uploading , i need to upload multiple image one by one to a div . 我在这里看到了一些链接,这些链接全部用于单个图像的上载,我需要一个一个地向div上载多个图像。

Can anybody help me thanks a lot in advance . 有人可以帮我多谢吗?

Your code require 2 changes 您的代码需要进行2次更改

1 : Its not element.files but element.target as element here is param resolve to event 1:它不是element.files而是element.target作为元素,这是对事件的参数解析

2 : .files is an array you need to select the first file by files[0] 2:.files是一个数组,您需要按文件选择第一个文件[0]

  $scope.imageUpload = function(element){
      var reader = new FileReader();
      reader.onload = $scope.imageIsLoaded;
      //console.log(element.target.files[0])
      reader.readAsDataURL(element.target.files[0]);

    }

See this fiddle http://jsfiddle.net/ADukg/9867/ 看到这个小提琴http://jsfiddle.net/ADukg/9867/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的类型错误:无法在“FileReader”上执行“readAsDataURL”:参数 1 的类型不是“Blob” - Uncaught TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 类型错误:无法在“FileReader”上执行“readAsDataURL”:参数 1 的类型不是“Blob” - TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 未捕获的TypeError:无法在“ FileReader”上执行“ readAsBinaryString”:参数1的类型不是“ Blob” - Uncaught TypeError: Failed to execute 'readAsBinaryString' on 'FileReader': parameter 1 is not of type 'Blob' 将博客转换为 base64:TypeError:无法在“FileReader”上执行“readAsDataURL”:参数 1 不是“Blob”类型 - Converting blog to base64: TypeError: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 有时会:无法在“FileReader”上执行“readAsDataURL”:参数 1 不是“Blob”类型 - Sometimes getting: Failed to execute 'readAsDataURL' on 'FileReader': parameter 1 is not of type 'Blob' 未捕获的 DOMException:无法在“FileReader”上执行“readAsDataURL” - Uncaught DOMException: Failed to execute 'readAsDataURL' on 'FileReader' 无法在&#39;FileReader&#39;上执行&#39;readAsText&#39;:参数1不是&#39;Blob&#39;类型 - failed to execute 'readAsText' on 'FileReader' :parameter 1 is not of type 'Blob' 无法在“FileReader”上执行“readAsArrayBuffer”:参数 1 的类型不是“Blob” - Failed to execute 'readAsArrayBuffer' on 'FileReader': parameter 1 is not of type 'Blob' 未捕获的 DOMException:无法在“FileReader”上执行“readAsDataURL”:该对象已在忙于读取 Blob。(...) - Uncaught DOMException: Failed to execute 'readAsDataURL' on 'FileReader': The object is already busy reading Blobs.(…) “未捕获的TypeError:fileReader.readAsDataurl不是函数”自动函数框问题 - “Uncaught TypeError: fileReader.readAsDataurl is not a function” Automatic Function Casing Problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM