【发布时间】:2018-09-01 16:48:25
【问题描述】:
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]);
}
}
<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)" />
我正在使用以下功能上传图像并将其发送到后端。问题是图像尺寸很大,到达后端需要时间。我已经看过很多关于如何压缩图像的示例,但我真的不想更改现有代码并修改模块,所以有人可以告诉我如何更改此功能并压缩图像。
【问题讨论】:
-
如果它符合您的需要,请考虑接受答案,它可以帮助社区,谢谢
标签: angular image-compression image-upload