A Way to Validate an Uploaded File Before Submitting

I have discovered something and would like to share it with the community, while at the same time would like to know if this is "safe" to be used, or whether the slightest code change in Appian might cause it to misbehave.

A way of validating the uploaded file before submitting it, like validation on extension, file size, file name...etc.

When searching in the forum, the answer is: "it is not possible to be done without actually submitting the form and doing the checks after submitting."

But I have found a way to get it to work, and below is the method:

In the validation of the upload fileUploadField, call the object a!fileUploadField, passing the variable "value:ri!MainImage", assuming you are saving into "ri!MainImage" and then calling any properties like "uploadedDocumentName" as needed. This has worked for me perfectly.

Below is a code snippet:
a!fileUploadField(
label: "Main Image",
labelPosition: "ADJACENT",
...

OriginalPostID-153370

OriginalPostID-153370

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer
    @ajinkyab277, this should be simple to debug - all you need to do is view the properties of the a!documentUploadField component when viewed as text output.

    i.e. an interface including a file upload field saving its upload value into a local variable, followed by this:
    a!paragraphField(
    value: a!documentUploadField(value: local!uploadedFile)
    )

    If someone could try this and post a screenshot, that would be helpful.

    My guess is that the background property name has been changed - this is a good example of why I suggest doing this functionality only within an encapsulated external rule and not hard-coded into forms.
Reply
  • 0
    Certified Lead Developer
    @ajinkyab277, this should be simple to debug - all you need to do is view the properties of the a!documentUploadField component when viewed as text output.

    i.e. an interface including a file upload field saving its upload value into a local variable, followed by this:
    a!paragraphField(
    value: a!documentUploadField(value: local!uploadedFile)
    )

    If someone could try this and post a screenshot, that would be helpful.

    My guess is that the background property name has been changed - this is a good example of why I suggest doing this functionality only within an encapsulated external rule and not hard-coded into forms.
Children
No Data