Question

I am trying to get multiple selected files and save into mysql

GSP CODE :

<input type="file" name="file_attachemnt" id="file_attachemnt" multiple/>

Controller Code For multiple file get

def all = request.getFileNames()

        all.each {name ->
           def file = request.getFile(name)
           def CommonsMultipartFile uploadedFile =file
           def fileName = uploadedFile.originalFilename
           println "file name "+fileName;
           def fileExtent=FilenameUtils.getExtension(fileName);
        }

But in controller side only one file i get.. even if i selected e.g 3 files

Was it helpful?

Solution

Give this a try. Not sure but I don't think much has changed since the 1.3.x days and this works there.

request.getMultiFileMap().file_attachemnt.each {
    println it.originalFilename
}

OTHER TIPS

Try this code

params.list("file_attachemnt").each{
// your code here
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top