Validate Uploaded File Extension

28 views
Skip to first unread message

Jamie Jackson

unread,
May 23, 2016, 4:59:42 PM5/23/16
to ValidateThis
Has anyone come up with a validator for checking file upload extensions?

I know the nuts and bolts for this, but I don't know how to make it happen in VT.

Nuts & Bolts:
  • Get the file name in JS: document.getElementById("attach_99").value
  • Get the file name in Lucee: 
    function getUploadFileName(required string formFieldName) {
    return getPageContext().formScope().getUploadResource(formFieldName).getName();
    }
I tried to see if I could manage to get the client-side part working with existing constructs, but it's not working:

...
<uform:fieldset legend="blah">
  <uform:field label="Attach File TEXT" name="attach_99" isRequired="false" type="file" />
</uform>
...

...
{"name":"attach_99","desc":"changeme",
"rules": [
{"type":"regex", "params" : [
{"name":"regex","value":".*\.pdf"}
]}
]
}
...

As a text input, this works fine.

For now, I'm doing server-side validation (separate from any explicit VT rules) and performing an addFailure() to add the issue into the validation object, but I'm not sure how to tackle the client-side.

Thanks,
Jamie
Reply all
Reply to author
Forward
0 new messages