如何解决运行我的文件更改事件侦听器导致 TypeError:无法在“FileReader”上执行“readAsArrayBuffer”:参数 1 的类型不是“Blob”
我正在尝试以角度上传多个图像。在文件输入元素上运行我的代码更改时,我收到错误“无法在'FileReader'上执行'readAsArrayBuffer':参数1不是'Blob'类型。”在浏览器控制台日志中。我的代码如下:
// listing gallery images
onFileChange(event) {
this.gallery = true;
if (event.target.files && event.target.files[0]) {
// clears some arrays
this.imagePaths = [];
this.galleryPreview = [];
const filesAmount = event.target.files.length;
for (let i = 0; i < filesAmount; i++) {
const file = event.target.files[i];
// checks file validity
if (!this.validateFile(file.name)) {
this.isValidFormat = false;
console.log('Selected file format is not supported');
return false;
}
this.isValidFormat = true;
// Assigns filelist value to form control
const files = event.target.files;
this.myForm.patchValue({
files: files
});
// handles image previews
const reader = new FileReader();
reader.onload = (event: any) => {
const file = event.target.result;
this.isValidFormat = true;
this.galleryPreview.push(file);
}
reader.readAsDataURL(event.target.files[i]);
}
}
this.gallery = false;
}
```
Every time i choose images i get the above error. Please point out the errors in my code.
The form is as follows:
```
this.myForm = new FormGroup({
title: new FormControl(null,{
validators: [Validators.required,Validators.minLength(3)],}),files: new FormControl(null,{
validators: [Validators.required],asyncValidators: [mimeType]}),tags: new FormControl(null,{ validators: [Validators.required] }),});
// subscription on start
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。