How do restrict users to upload (e.g = or > 1MB) image size for a particular image field using python code?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客户关系管理
- e-Commerce
- 会计
- 库存
- PoS
- Project
- MRP
此问题已终结
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;
}
})
相关帖文 | 回复 | 查看 | 活动 | |
---|---|---|---|---|
|
0
6月 21
|
2493 | ||
|
2
6月 17
|
8776 | ||
|
1
5月 23
|
2766 | ||
|
1
2月 25
|
4223 | ||
|
1
4月 19
|
9980 |