[英]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次更改
$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.