Forum Discussion

AngelaIp's avatar
AngelaIp
Ideator I
6 years ago
Solved

How to add restrictions to aras.vault.selectFile() file picker

Hi community, I currently design a custom form with a button that calls a regular file picker. In my scenario, end users shall only be able to upload certain datatypes, like txt and xml. As the aff...
  • Hi Angela,

    The file picker is basically just using a standard HTML input element with the file type. This file input type supports an additional attribute called accept which you can use to pass in a comma separated list of extensions and mime types that you want your users to be able to pick from. There's a good explanation of it with some nice examples on this StackOverflow answer. In your case, you'd want to set an attribute like accept=".txt, .xml" . Note that in most browsers this will typically apply a default filter, but users will still be able to opt out of the filter to select any file they want. Because of this, your checks on the file once it's returned should still be included.

    For your use case, I'd recommend using a custom file input element rather than the one used by the selectFile() function which exists in the codetree. This will make it easier to modify in the future as well as allow for the possibility of accepting different file types for different users or situations.


    Chris

    Christopher Gillis

    Aras Labs Software Engineer