Remove file immediately, if extension is not "PDF"

Certified Associate Developer

HI All,

I am using a!fileUploadField for uploads file, which has validated to allow only "PDF" file, 

Our ask is, if uploaded file extension is not PDF, shall remove immediately, how i can do that?

Note:- file upload feature i have given on a grid column and it's single select.

  Discussion posts and replies are publicly visible

Parents Reply
  • 0
    Certified Lead Developer
    in reply to Stefan Helzle

    This can be done by using the "content details" plug-in which can also access object properties by ID for freshly-uploaded files (though annoyingly the output is only plaintext so we must scrape the result).  I've switched to that method for the times when it's truly necessary.

    /* Parent Rule =  UTIL_getNewUploadDocName */
    a!localVariables(
      local!rawDetails: if(
        a!isNullOrEmpty(ri!doc),
        "",
        getcontentobjectdetailsbyid(ri!doc)
      ),
      local!wholeName: index(extract(
        local!rawDetails,
        "[Name: ",
        ", UUID:"
      ), 1, null()),
    
      rule!UTIL_processDocumentName(
        docName: local!wholeName
      )
    )

    /* Child Rule = UTIL_processDocumentName (uses RegEx plug-in) */
    a!localVariables(
      local!hasNoExtension: search(".", ri!docName) = 0,
      
      local!namePart: if(
        local!hasNoExtension,
        ri!docName,
        regexsearch(
          pattern: ".*(?=\.)",
          searchString: ri!docName,
          regexFlags: "i"
        )[1].match
      ),
      
      local!extension: if(
        local!hasNoExtension,
        "",
        regexsearch(
          pattern: "[^\.]*$",
          searchString: ri!docName,
          regexFlags: "i"
        )[1].match
      ),
      
      a!map(
        name: local!namePart,
        extension: local!extension
      )
    )

    Result:

    cc: please consider adopting this method instead of the unsupported component-hacking that was formerly required for this functionality, at least in terms of what we recommend to people around here Slight smile

Children
No Data