Upload multiple files to Grails

I am trying to integrate the excellent jquery-file-upload from blueimp into Grails 2.0 and write a new plugin for it. I know that it is already a plugin , but it does not use resources and has not been updated for 9 months, and jquery-file-loading has changed a lot during this time.

So, I put all the distribution files in my plugin, and now I'm trying to write a controller action that can handle the download. The problem is that request.getFileNames() gives only one files[] entry, and I don't know how to get 3 separate files that I upload.

How do you process files sent using this input: <input type="file" name="files[]" multiple> ?

+7
source share
2 answers

Actually, I realized that. There is only one input[type=file] in the form, and if I select several files, they will not be sent on the same request. query-file-upload script sends as many POST requests as there are files. This is why request.getFileNames() gives me only one entry each time. I managed to create my plugin, it will be published soon. Watch out for http://grails.org/plugin/bootstrap-file-upload .

+4
source

request.getFileNames returns an array - you can iterate over this array to get all the files. An example is already present in the plugin description.

 def all = request.getFileNames() all.each {name -> def file = request.getFile(name) } 

This should provide you with all the files that have been downloaded.

+2
source

All Articles