importClass(Packages.com.filenet.api.action.Create);
importClass(Packages.com.filenet.api.exception.EngineRuntimeException);
importClass(Packages.com.filenet.api.core.ContentTransfer);
importClass(java.lang.System);
importClass(java.util.HashSet);
function preprocessObjectChange(sourceObj) {
var actions = sourceObj.getPendingActions();
var isCreate = false;
if (actions != null) {
for (var i = 0; i < actions.length; i++) {
if (actions[i] instanceof Create) {
isCreate = true;
break;
}
}
}
if (!isCreate) return true;
// Allowed extensions as a Java HashSet
var allowedSet = new HashSet();
allowedSet.add("pdf");
allowedSet.add("txt");
var MAX_SIZE = 10 * 1024 * 1024; // 10 MB
var contentList = sourceObj.get_ContentElements();
if (contentList == null || contentList.size() == 0) return true;
for (var i = 0; i < contentList.size(); i++) {
var ce = contentList.get(i);
if (ce instanceof ContentTransfer) {
var fileName = String(ce.get_RetrievalName()).toLowerCase();
var ext = String(fileName.substring(fileName.lastIndexOf(".") + 1)).trim();
System.out.println("Extension detected: [" + ext + "]");
if (!allowedSet.contains(ext)) {
System.out.println("Extension rejected: " + ext);
return false;
}
var sizeBytes = ce.get_ContentSize().intValue();
System.out.println("Detected Size: " + sizeBytes + " bytes");
if (sizeBytes > MAX_SIZE) {
System.out.println("File too large: " + sizeBytes);
return false;
}
}
}
System.out.println("All validations passed.");
return true;
}
In the above code, the restriction based on file extensions is working correctly, but the file size cannot be restricted because it gives the following error:
"The content size property was not found in the properties collection."
How can this issue be resolved?
------------------------------
Wasif Khan
------------------------------
Original Message:
Sent: Sun November 16, 2025 01:12 PM
From: Ganesh Jamdade
Subject: Limit file size and restrict file types in ICN attachment widget
This restriction of files types and size can be done using "Change Pre processor" which is very quick solution to implement . You can also customize the error message that you are throwing to user.
instead of going for widget customization this will be quick and reliable solution. This will ensure to invoke checks no matter from where the contents comes from.
------------------------------
Ganesh Jamdade
Original Message:
Sent: Wed November 12, 2025 05:43 AM
From: Wasif Khan
Subject: Limit file size and restrict file types in ICN attachment widget
Hi after installing the plugin exactly how and where can we restrict file types ?
------------------------------
Wasif Khan
Original Message:
Sent: Thu October 27, 2022 08:23 AM
From: Mark Jordan
Subject: Limit file size and restrict file types in ICN attachment widget
Hello -
You can investigate using this ICN plugin: https://github.com/ibm-ecm/ibm-content-navigator-samples/tree/master/DocumentUploadFilterPlugin
You can use it to restrict specified mime types from being ingested via ICN. There are currently no available methods to restrict fie size but you can work to use the DocumentUploadFilterPlugin code to possibly add in file size restrictions.
-Mark
------------------------------
Mark Jordan
Original Message:
Sent: Fri October 21, 2022 01:33 AM
From: Nagajyothi Kommareddy
Subject: Limit file size and restrict file types in ICN attachment widget
Team,
Please suggest me the best way to restrict few filetypes and limit the size of files while adding a document from the case information or work details page, by showing a proper error message to the user.
We are using ICN 3.0.5.
Thanks in advance.
------------------------------
Nagajyothi Kommareddy
------------------------------