How can I store the exact size of the file being uploaded in a variable?

I am facing a problem where I want to store the exact size of an uploading file in a variable so that I can access it later to validate even if the section containing the file upload field is hidden. I am on v19.1. PS. By size, I mean the exact size in bytes and not "<1KB" which is retrieved by using fv!files.size. I cannot use a!save() function in validation attribute and fv!files.size is not accessible outside validation.

  Discussion posts and replies are publicly visible

Parents Reply
  • If it's just a matter of not letting files of a certain size be uploaded, then the current OOTB functionality should be fine for you since you can access the file sizes directly within the "validations" parameter of a!fileUploadField.

    (Edit: as I noted in a different reply below, "fv!files.size" contains the file sizes in bytes, NOT the "display value" i.e. "<1KB".)

    a!fileUploadField(
      value: ri!doc,
      saveInto: ri!doc,
      maxSelections: 1,
      validations: {
        if(
          fv!files.size = 0,
          "Empty documents not allowed.",
          null()
        )
      }
    )

Children
No Data