Validate uploded document size getting error message saying that Invalid function fileUploadField_17r1

We are on 17.1 version of Appian, I have a requirement to validate the uploaded document size

I have a requirement to validate the uploaded document size. Once the user has uploaded the file needs to be validated before submitting the form. so here I can not use document function.

tried several approaches like

a!fileupload(

value:ri!document,

target:"ABC LOCATION"

).uploadedDocumentSize

the above approach is working in expression rules but at run time it is giving me an error saying that text can not convert to Layout.

Approach 2

a!fileUploadField_17r1(
value: ri!document
).uploadedDocumentSize

 

Above approach is giving error message saying that Invalid function fileUploadField_17r1

 

  Discussion posts and replies are publicly visible

  • hi chandolum,

    try below code,

    a!fileUploadField(

                   label:"",

                   target: "ABC LOCATION",

                   value: ri!document,

                   saveInto: ri!document,

                   validations: {

                     if(

                       fv!files.size>1000000,

                       "file size should not be greater than 1000 KB",

                       ""

                     )

                   }

                 )

  • As per my understanding, we don't have a provision of getting the size of the file we upload in 17.1.
    But we have one in 17.2 onward. As have shared the code for the size validation
  •  Thank you all for your response,

    the above-attached code snippet solved my problem

    root cause: In 17.1 version, file upload component is having a different set of attributes in design view and in the live view (execution time)

    if(
      or(
        rule!APN_isBlank(
          ri!document
        ),
        tointeger(
          ri!document
        ) <= 0
      ),
      {
        fullName: "",
        name: "",
        ext: "",
        size: ""
      },
      with(
        local!value: a!fileUploadField(
          value: ri!document
        ),
        if(
          rule!APN_isBlank(
            property(
              local!value,
              "uploadedDocumentName",
              null()
            )
          ),
          /* get properties as rendered in 17.1+ process forms */
          if(
            rule!APN_isBlank(
              property(
                property(
                  local!value,
                  "contents",
                  null()
                ),
                "name",
                null()
              )
            ),
            {
              fullName: "",
              name: "",
              ext: "",
              size: ""
            },
            {
              fullName: local!value.contents.name & "." & local!value.contents.extension,
              name: local!value.contents.name,
              ext: local!value.contents.extension,
              size: local!value.contents.size
            }
          ),
          /* for old style form rendering (pre-17.1, or in 17.1 interface designer) */
          with(
            local!fullName: local!value.uploadedDocumentName,
            local!parts: split(
              local!fullName,
              "."
            ),
            local!extension: if(
              length(
                local!parts
              ) > 1,
              index(
                local!parts,
                length(
                  local!parts
                ),
                ""
              ),
              ""
            ),
            local!name: if(
              length(
                local!parts
              ) > 1,
              joinarray(
                rdrop(
                  local!parts,
                  1
                ),
                "."
              ),
              index(
                local!parts,
                1,
                ""
              )
            ),
            {
              fullName: local!fullName,
              name: local!name,
              ext: local!extension,
              size: local!value.uploadedDocumentSize
            }
          )
        )
      )
    )

  • 0
    Certified Lead Developer
    in reply to chandolum
    Glad to see my 17.1 code has found its way here as well - in 17.2 they've luckily made this a bit easier on us (as the designer / front-end interfaces are now consistent).

    One thing to keep in mind: the size returned in the 17.1 (and earlier) back-end is a text rendering (i.e. "2kb", "2mb", etc), and therefore it's VERY approximate. To do any meaningful size comparison you'll both have to parse the returned text and also accept limiting the capability of your filesize validation to something that can use the approximate value this makes available to you. In 17.2 and up, a file size in bytes is returned, which will make this sort of thing a lot easier going forward.