I have a file upload input with the following HTML:
<input type="file" id="assets" name="assets" multiple="multiple" webkitdirectory="webkitdirectory">
I am able to upload a single file like so:
single_file = "/Users/me/Downloads/Demo Folder/1428441/1.wav"
upload = @browser.file_field(:id => 'assets')
upload.set single_file
However, when I try to upload multiple files, by selecting the top-level directory (which works if I try doing this in my browser manually):
assets_folder = "/Users/me/Downloads/Demo Folder/1428441"
puts "Does dir exist? #{File.directory?(assets_folder)}" # true
upload = @browser.file_field(:id => 'assets')
upload.set assets_folder
It fails to upload at all. If I try creating a array containing the filepaths of 2 different files:
files = []
files.push("/Users/me/Downloads/Demo Folder/1428441/1.wav")
files.push("/Users/me/Downloads/Demo Folder/1428441/2.wav")
upload = @browser.file_field(:id => 'assets')
upload.set files
I see that this method only accepts a string as a parameter: can't convert Array into String (TypeError)
Is it at all possible to select multiple files via the file_field
's set
method?
If not, what other workarounds could I try? I briefly looked at trying to inject JavaScript but apparently that's not possible either, according to "How to set a value to a file input in HTML?"