Search code examples
grailsgrails-controller

How to process a CommonsMultipartFile


I'm trying to implement upload code for grails. When the file is processed on my controller I get this error:

ERROR errors.GrailsExceptionResolver  - Exception occurred when processing request: [POST] /com.jason.score/fileResource/uploads
Stacktrace follows:
groovy.lang.MissingMethodException: No signature of method: static org.hsqldb.types.Binary.storeMyFileMethod() is applicable for argument types: (org.springframework.web.multipart.commons.CommonsMultipartFile) values: [org.springframework.web.multipart.commons.CommonsMultipartFile@1a17db8]
    at com.jason.score.FileResourceController$_closure4_closure6.doCall(FileResourceController.groovy:73)
    at com.jason.score.FileResourceController$_closure4.doCall(FileResourceController.groovy:72)
    at com.jason.score.FileResourceController$_closure4.doCall(FileResourceController.groovy)
    at java.lang.Thread.run(Thread.java:662)

My controller function looks like this:

  def uploads = {
    Collection result = []
    Binary binary
    request.getFileNames().each {
        binary = Binary.storeMyFileMethod(request.getFile(it))
        result << [name: binary.getFileName(), size: binary.getFileSize()]
    }
    render result as JSON
}

My view looks like this:

  <g:form name="fileupload" url="[action:'uploads',controller:'fileResource']" method="POST" enctype="multipart/form-data">
           ....
            <input type="file" name="files[]" multiple>

  </g:form>

Can anyone explain what is going wrong and how I can process each file that is uploaded (can be multiple files)?


Solution

  • @jason Did you installed grails jquery plugin? If yes did you do that before running the app or after running the application? make sure jquery plugin in classpath and organize your imports. By the error message it looks like jquery jar's not in classpath and your application is trying to use org.hsqldb.types.Binary which you are not supposed to use for file uploads.