AngularJS在文件上传前判断文件大小,并且进行超限提示

废话不说,直接上代码:
html代码,兼容移动端浏览器:

	<input type="file" name="and_file_head" id="and_file_head" accept="image/*" capture="camera" style="display: none;">
	<input type="file" name="file_head" id="file_head" accept="image/*" style="display: none;" />

js代码:

	$("#file_head,#and_file_head").change(function(){
		if(!allowFile(this.files[0], fileset)){
            $("#file_head,#and_file_head").val(null);  // 防止用户两次选择同一个文件
			return;
		}
		
		var objUrl = getObjectURL(this.files[0]);
		
	 	if (objUrl) {
	 		$scope.validLocalids.push(objUrl);
	 		$scope.$apply();
	 	}
	 	
	    new ImageCompressor(this.files[0], compressOptions);
	});

 

欢迎关注我的微信公众号:

 

如无特殊说明,文章均为本站原创,转载请注明出处!

发表回复

您的电子邮箱地址不会被公开。