Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用angular js上传文件时如何对图像大小进行验证_Javascript_Angularjs_File Upload - Fatal编程技术网

Javascript 使用angular js上传文件时如何对图像大小进行验证

Javascript 使用angular js上传文件时如何对图像大小进行验证,javascript,angularjs,file-upload,Javascript,Angularjs,File Upload,我正在研究角度应用。我使用上传图像。这是我的HTML代码 <ul class="enlarge col-lg-9 margin_top10"> <li ng-repeat="image in images"> <img id="pic1" src="{{image.photoPath}}" ng-click="readImageUrl();" style="height: 40px; w

我正在研究角度应用。我使用
上传图像。这是我的HTML代码

    <ul class="enlarge col-lg-9 margin_top10">
    <li ng-repeat="image in images">
        <img id="pic1"
            src="{{image.photoPath}}" ng-click="readImageUrl();"
            style="height: 40px; width: 50px;"/> 
            <span>
                <img src="{{image.photoPath}}"
                style="height: 200px; width: 400px;" id="pic2"/> 
            </span>
        <a href="javascript:void(0)" ng-click="deletePhoto(image.photoPath,$index)" title="Delete">&times;</a>

    </li>
    <li id="selectedPhotos" style="width:700px;height:100px;float:left;"></li>

</ul>

图像将成功上载并保存。但我想给验证像用户不能上传图像大小超过1 MB。我不知道怎么做。请分享你的想法。提前谢谢

理想情况下,您可以在服务器上进行验证。这是一种选择吗?
$scope.readImageUrl = function() {
                    try {
                        var input = document.getElementById("fileSel");
                        if (input.files && input.files[0]) {
                            /* if(input.files.length==1){
                                $("#demo").show();
                            } */
                            var xhr = new XMLHttpRequest();
                            xhr.open('GET', input.files[0], true);
                            xhr.responseType = 'blob';
                            xhr.onload = function(e) {
                                localSrc = URL
                                        .createObjectURL(this.response);
                            };
                            xhr.send();
                            var reader = new FileReader();
                            reader.onload = function(e) {
                                $('#profilePic1').attr('src',
                                        e.target.result);
                                $('#profilePic2').attr('src',
                                        e.target.result);
                            }
                            reader.readAsDataURL(input.files[0]);
                        }
                    } catch (ex) {
                        console.log(ex);
                    }
                };