I'm using Grails 2.4.3 and I have a <g:uploadForm>
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:
<g:uploadForm method="POST" action="uploadSupplemental" >
<div class="modal-header">
<h3 class="modal-title" id="myModalLabel">Upload Supplemental Data File</h3>
</div>
<div class="modal-body">
<label for="fileInput">Choose file to upload:</label>
<input type="file" id="fileInput" name="supplementalData" />
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<input type="submit" class="btn btn-primary" />
</div>
</g:uploadForm>
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
Here is a related JIRA issue and a duplicate question in SO reporting the same exception.
Also make sure the user is authenticated (with @Secured
) before the upload action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With