shrine-rails-example
shrine-rails-example copied to clipboard
Only allow one file selection for 'cover' non-multiple input
The "cover" photo only accepts one file, but was resulting in a file open dialog that let you pick multiple files -- all but the first would be ignored by subsequent JS code.
This now demonstrates how to tell uppy to (tell the OS file selection dialog to) only allow one file selection.
Since we're just using the html "multiple" attribute, I'm not sure why uppy doesn't do this already as a default, it could conceivably be a feature PR to uppy. But in the meantime, why not have the demo be more solid and take care of this. Without this change, the demo lets me choose more than one file for 'cover' but they are all ignored; with this change, the demo file open dialog for 'cover' only lets me choose one file. (MacOS Chrome).
I initially added the limitation, but it turns out that when using the FileInput plugin, the maxNumberOfFiles option doesn't only limit the amount of files you can upload in one selection, but the total amount of files you can upload for that input. For example, with maxNumberOfFiles: 1, if I upload the file, then change my mind and want to upload a different file, I can't, because I already uploaded the maximum number of files I was allowed to (which is 1).
I think that behaviour doesn't make sense at all when using the FileInput plugin, so I opened an issue – https://github.com/transloadit/uppy/issues/837. You can chime in there if you want.
The FileInput plugin should IMO provide an option for only toggling the multiple HTML attribute, but still allowing you to upload as much as you want. Or somehow change maxNumberOfFiles to mean "at once" instead of "in total".