: File Upload Validation Not Working for PDF Restriction

Certified Associate Developer

I am facing an issue with the a!fileUploadField() component in Appian. The validation logic is supposed to restrict uploads to only PDF files, but it is not throwing an error when an XLSX file is uploaded. Below is my implementation:

a!fileUploadField(
    label: "File Upload",
    labelPosition: "ABOVE",
    target: cons!W500_KnowledgeCenter,
    maxSelections: 5,
    value: ri!File,
    saveInto: ri!File,
    validations: {
        if(fv!files.extension="PDF", "Error", "")
    }
)

  Discussion posts and replies are publicly visible

Parents Reply
  • +1
    Certified Lead Developer
    in reply to sureshkumarj8140

    "fv!files" is a list.  if you say "fv!files.extension = "pdf"", it will be asking Appian if the entire list of extensions is equal to the exact string "pdf", which it obviously won't be. 

    You will need to rewrite your code in such a way that you check all entries in the "fv!files" list for invalid extensions.

    Hence the example Stefan linked:

    e.g.

    a!localVariables(
      
      local!file: {},
      
      a!fileUploadField(
        value: local!file,
        saveInto: local!file,
        maxSelections: 3,
        validations: {
          if(
            contains(fv!files.extension, "pdf"),
            "no pdf allowed",
            ""
          )
        }
      )
    )

    ...which works perfectly when I try it.

Children