I'm using Grails 2.4.3 and I have a with method set to post, but I'm not getting a MutlipartRequest in my controller action. Instead I'm getting a Servlet3SecurityContextHolderAwareRequestWrapper which has not getFile() method. I've tried casting, I've tried getting the request out of the wrapper with request.request, and I've tried a bunch of other things I've seen suggested to others with a similar problem, but still no dice. I'm sure I'm missing something simple. I tend to do that, but if anyone can point me in the right direction, I'd be very grateful.
Here's my form:
Upload Supplemental Data File
Choose file to upload:
And here's my controller action:
def uploadSupplemental() {
MultipartRequest multipartRequest = request as MultipartRequest
def file = multipartRequest.getFile('supplementalData')
if (file){
flash.message = "File found!!"
} else {
flash.message = "File NOT found. :-( "
}
redirect action:'list'
}
And here's the error I get:
URI /app/upload/uploadSupplemental Class
groovy.lang.MissingMethodException Message No signature of method:
org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper.getFile()
is applicable for argument types: (java.lang.String) values:
[supplementalData] Possible solutions: getXML(),
getPart(java.lang.String), getAt(java.lang.String),
getAt(java.lang.String), getLocale(), getJSON()
解决方案
The following config property has to be set to true in Config.groovy in order to enable multipart requests.
grails.web.disable.multipart=true
Also make sure the user is authenticated (with @Secured) before the upload action.