We are currently working on implementing a maximum size limit of 2mb for images using ng2-file-upload. Below is the code snippet:
uploader: FileUploader = new FileUploader({
url: URL,
disableMultipart: true
});
...
...
OnFileSelected(event) {
const file: File = event[0];
this.ReadAsBase64(file)
.then(result => {
this.selectedFile = result;
})
.catch(err => console.log(err));
}
Upload() {
if (this.selectedFile) {
this.usersService.AddImage(this.selectedFile).subscribe(
data => {
this.socket.emit('refresh', {});
console.log(data);
},
err => console.log(err)
);
}
}
ReadAsBase64(file): Promise<any> {
const reader = new FileReader();
const fileValue = new Promise((resolve, reject) => {
reader.addEventListener('load', () => {
resolve(reader.result);
});
reader.addEventListener('error', event => {
reject(event);
});
reader.readAsDataURL(file);
});
return fileValue;
}
We are looking for guidance on where and how to enforce the image size limit. Any suggestions?