In ejs-uploader after selecting the image need to show the validation message if the image dimensions exceeds the specified dimensions and upload button should be disabled.
In the above screenshot validation for image size is taking place , In the same scenario for the image dimensions as well we need to restrict it by showing a validation message and restricting to upload.
can you please show the to achieve it.
|
public onSelect(args) {
var reader = new FileReader();
reader.readAsDataURL(args.filesData[0].rawFile);
reader.onload = function(e) {
var image = new Image();
image.src = e.target.result;
image.onload = () => {
var height = this.height;
var width = this.width;
console.log(this);
if (
(height >= 1024 || height <= 1100) &&
(width >= 750 || width <= 800)
) {
alert('Height and Width must not exceed 1100*800.');
var upload = document.getElementById('defaultfileupload');
upload.ej2_instances[0].l10n.currentLocale.uploadSuccessMessage =
'File size exceed';
return false;
}
alert('Uploaded image has valid Height and Width.');
return true;
};
};
} |
Hi Berly,
Thank you for responding I have tried this sample but I was getting the below error,
can you please show a solution for this issue.
|
upload!.ej2_instances[0].l10n.currentLocale.uploadSuccessMessage ='File size exceed'; |
|
(upload as any).ej2_instances[0].l10n.currentLocale.uploadSuccessMessage ='File size exceed'; |
Hi Prince,
Thank you for responding, I have tried the code snippet, it is working like this
The message is displaying after clicking on upload.
I need the message before uploading the image and it should be in red color as a failure scenario and upload needs to be restricted. Can you please find a solution for this.
Thanks,
Lahari Navudu
Hi Berly,
The message is displaying after clicking on upload.
I need the message before uploading the image and it should be in red color as a failure scenario and upload needs to be restricted. Can you please find a solution for this.
Thank you
Lahari Navudu
|
public onSelect(args) {
var reader = new FileReader();
reader.readAsDataURL(args.filesData[0].rawFile);
reader.onload = function(e) {
var image = new Image();
(image as any).src = e.target.result;
image.onload = function() {
var height = this.height;
var width = this.width;
console.log(this);
if (
(height >= 1024 || height <= 1100) &&
(width >= 750 || width <= 800)
) {
alert('Height and Width must not exceed 1100*800.');
var upload = document.getElementById('defaultfileupload');
document.querySelector('.e-file-status').innerHTML =
'File size exceed';
document.querySelector('.e-file-status').style.color = 'red';
document
.querySelector('.e-file-upload-btn')
.classList.add('e-disabled');
return false;
}
alert('Uploaded image has valid Height and Width.');
document.querySelector('.e-file-status').style.color = 'green';
document
.querySelector('.e-file-upload-btn')
.classList.remove('e-disabled');
return true;
};
};
} |
Hi Berly,
Thank you for responding, but I was getting the below error after trying this code snippet.
Can you please show me a solution for this one.
Thank you,
Lahari Navudu
|
document.querySelector('.e-file-status')!.innerHTML ='File size exceed'; |
|
document.querySelector<HTMLElement>('.e-file-status').style.color ='red'; |