Content Management and Capture

Content Management and Capture

Come for answers. Stay for best practices. All we’re missing is you.

 View Only
  • 1.  Limit file size and restrict file types in ICN attachment widget

    Posted Fri October 21, 2022 01:33 AM
    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
    ------------------------------


  • 2.  RE: Limit file size and restrict file types in ICN attachment widget

    Posted Wed October 26, 2022 03:52 PM
    Hi Nagajyothi, 

    I'm going to move your question to the content forum for more visibility and see if we can find an answer for you. 

    Thanks

    ------------------------------
    Stephanie Wilkerson
    IBM
    ------------------------------



  • 3.  RE: Limit file size and restrict file types in ICN attachment widget

    Posted Thu October 27, 2022 08:23 AM
    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
    ------------------------------



  • 4.  RE: Limit file size and restrict file types in ICN attachment widget

    Posted Fri October 28, 2022 10:19 AM
    Hi... I assume you are using FileNet as a repository.

    In that case, you can create a CodeModule with a Java class to do the validation and if the document size exceeds the limit, throw an exception. Then create an Event Action with that Java class and a Subscription to your document class that triggers validation on the Create and Checkin events.

    With this approach, you have your validation regardless of the method used to upload the document to the repository.

    I hope this helps.

    ------------------------------
    Saludos/Regards.
    Sergio Salinas
    DBA ECM Consultant, IBM Expert Labs.

    ------------------------------



  • 5.  RE: Limit file size and restrict file types in ICN attachment widget

    Posted Mon October 31, 2022 10:49 AM
    Hi ,

    You can also do frontend validation to restric the filesize by extending addContentitem dialog on add function. 


    Thanks,
    Ravi Teja 


    --
    Best Regards,
    Ravi Teja M.
    +91 9030529333.





  • 6.  RE: Limit file size and restrict file types in ICN attachment widget

    Posted Wed November 12, 2025 09:13 AM

    Hi after installing the plugin exactly how and where can we restrict file types ?



    ------------------------------
    Wasif Khan
    ------------------------------



  • 7.  RE: Limit file size and restrict file types in ICN attachment widget

    Posted 30 days ago

    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
    ------------------------------



  • 8.  RE: Limit file size and restrict file types in ICN attachment widget

    Posted 27 days ago
    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
    ------------------------------