Search code examples
javascripthtmlinputfilelist

setting an input control's Filelist to a previously selected Filelist


In my web app, the user selects local images via input type='file'. The app has multiple 'brushes' and, for each brush, the user can select a different set of local images to be used as 'paint' by the brush. If possible, I would like to use just one input type='file' and, when a given brush X is the editable brush (only one brush at a time is editable), I'd like to refresh the input so that its Filelist is the editable brush's Filelist, not simply the most recently selected bunch of files. I expect this is not possible. Is that right?


Solution

  • You wouldn't be able to set the FileList on an input control programmatically as that would imply that you could read (or re-upload) files that the user had not just selected manually (security risk.)

    Maybe what you could do instead is compromise on the "I would like to use just one input type='file'" part. You could have an array of the input type='file' elements, and then show/hide them depending on which brush is selected. That would give the illusion of showing a different list of selected files in the UI.