Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2103 มุมมอง

How do restrict users to upload (e.g = or > 1MB) image size for a particular image field using python code?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hello Haris Masqati,

You can set image upload size validation error with js.

Find Example in comment.

I hope this will help you.

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

อวตาร
ละทิ้ง

For Example -

$('input[name="attachment"]').change(function(){
var fileInput = document.getElementById('test_id');
var files = fileInput.files;
/ checking for greater than or equals to 2MB file size /
for (let i = 0; i < files.length; i++) {
var fileSize = files[i].size;
/ 1024 = 1MB /
var size = Math.round((fileSize / 1024));
if (size > 2*1024) {
alert("Invalid file size, please select a file less than or equal to 2mb size");
fileInput.value = '';
return false;
}
}

}
if(files.length==0){
alert("Please choose a file first...");
return false;
}

})

Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มิ.ย. 21
2225
2
มิ.ย. 17
8458
1
พ.ค. 23
2463
1
ก.พ. 25
3915
1
เม.ย. 19
9600