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
    This is exciting. It never occurred to me that passing the local Document-type variable back into a!fileUploadField might allow access to the filename of the uploaded document via a dot-property (that's the real key here, in case anyone's wondering).

    The one precaution i'd advise here, since this doesn't seem to be an "officially supported" feature, is that we're not guaranteed that the dot properties of a!fileUploadField will be consistent in future versions - so it may be safest to wrap that logic in an expression rule where, for example, you pass in the ri!uploadedDocument and it returns the plaintext filename - just in case the dot property ".uploadedDocumentName" changes in the future, for example.
Reply
  • 0
    Certified Lead Developer
    This is exciting. It never occurred to me that passing the local Document-type variable back into a!fileUploadField might allow access to the filename of the uploaded document via a dot-property (that's the real key here, in case anyone's wondering).

    The one precaution i'd advise here, since this doesn't seem to be an "officially supported" feature, is that we're not guaranteed that the dot properties of a!fileUploadField will be consistent in future versions - so it may be safest to wrap that logic in an expression rule where, for example, you pass in the ri!uploadedDocument and it returns the plaintext filename - just in case the dot property ".uploadedDocumentName" changes in the future, for example.
Children
No Data