我在表单提交时使用ngFileUpload
将图片上传到服务器。
我可以上传图片,它会在屏幕上显示没有问题。但是,一旦我点击提交,我就会收到pattern
错误。当我随后从输入中删除图像时,我可以提交表单,并且图像实际上已提交,因为它尚未在控制器中删除。
这是我的HTML:
<div class="col-xs-12 col-sm-4 img-responsive">
<h4>Product Featured Image:</h4>
<div ngf-drop ngf-select ng-model="vm.product.featured_image" class="drop-box"
name="featured_image" ngf-drag-over-class="'dragover'"
accept="image/*" ngf-pattern="'image/*'" ngf-max-size="2MB"
ngf-change="vm.upload($files, $invalidFiles)">
<span>Drop</span>
<div class="col-xs-12" ng-show="vm.product.featured_image">
<img ngf-src="vm.product.featured_image" class="img-responsive">
</div>
</div>
<div class="text-center text-red" ng-show="editForm.featured_image.$error.maxSize">
Max file size is 2MB. File size: {{errorFile.size / 1000000|number:1}}MB
</div>
我的控制器方法:
upload($files, $invalidFiles) {
if ($files.length > 0) {
let fileR = new FileReader();
fileR.onloadend = ((e) => {
this.product.featured_image = e.target.result;
});
fileR.readAsDataURL($files[0]);
}
}