save(event: any, type, image_type) {
this.uploadImageFlag = true;
const fileList: FileList = event.target.files;
if (fileList.length > 0) {
const file: File = fileList[0]
this.files.set('files', file, file.name)
const reader = new FileReader();
reader.onload = (event: any) => {
this.url2 = event.target.result;
this.upload = true;
}
reader.readAsDataURL(event.target.files[0]);
}
}Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<input id="input" type="file" accept="image/*" style=" width: 180px;" #files (change)="save($event)" />Run Code Online (Sandbox Code Playgroud)
我正在使用以下功能上传图像并将其发送到后端。问题是图像大小非常大,需要时间才能到达后端。我看过很多关于如何压缩图像的例子,但我真的不想改变我现有的代码和修改模块,所以有人可以告诉我如何改变这个函数并压缩图像。