I building a web app using Grails 2.3.8 I have a feature where I can upload videos so I can later download them. Before we implemented the spring security both the download and upload feature were working. After implementation attempting to upload a video gives this error.
No signature of method: org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper.getFile() is applicable for argument types: (java.lang.String) values: [mp4Name] Possible solutions: getXML(), getPart(java.lang.String), getAt(java.lang.String), getAt(java.lang.String), getLocale(), getJSON()
I took a look at this link and tried what it said but I keep getting the same error. How do I get a MultipartRequest out of a Servlet3SecurityContextHolderAwareRequestWrapper
This is my form code
<div class="fieldcontain ${hasErrors(bean: videoInstance, field: 'fileName', 'error')} required">
<label for="fileName">
<g:message code="video.fileName.label" default="Video Name" />
<span class="required-indicator">*</span>
</label>
<g:textField name="fileName" required="" value="${videoInstance?.fileName}"/>
<div class="fieldcontain ${hasErrors(bean: videoInstance, field: 'mp4File', 'error')} required">
<label for="mp4NameT">
<g:message code="video.videoPath.mp4.label" default="Mp4 Path" />
<span class="required-indicator">*</span>
</label>
<g:textField name="mp4NameT" required="" value="${videoInstance?.mp4File}" readonly=""/>
<input type="file" id="mp4Name" name="mp4Name">
The above is the same for four more video file types. f4v, mov, 3gp, and 3gp light. and this is the section that has my save method for videos
@Transactional
def save() {
def videoInstance = new Video()
bindData(videoInstance, params, [exclude: ['mp4File']])
videoInstance.properties = params
if (videoInstance == null) {
notFound()
return
}
def dest = new File('web-app/videos')
def destOut = "/videos"
if(!dest.exists()) dest.mkdirs()
videoInstance.validate()
MultipartRequest multipartRequest = request as MultipartRequest
MultipartFile mp4F= multipartRequest.getFile('mp4Name')
MultipartFile f4vF= multipartRequest.getFile('f4vName')
MultipartFile movF= multipartRequest.getFile('movName')
MultipartFile gpF = multipartRequest.getFile('gpName')
MultipartFile lightF=multipartRequest.getFile('lightName')
if (mp4F.empty||f4vF.empty||movF.empty||gpF.empty||lightF.empty) {
println 'empty'
flash.message = 'file cannot be empty'
render(view:'_form')
}
else{
println 'not empty'
def mp4Namer=params.fileName+'.mp4'
def f4vNamer=params.fileName+'.f4v'
def movNamer=params.fileName+'.mov'
def gpNamer =params.fileName+'.3gp'
def lightNamer=params.fileName+'_Light.3gp'
videoInstance.mp4File=''+'web-app/videos/'+mp4Namer
mp4F.transferTo( new File('web-app/videos/'+mp4Namer))
videoInstance.f4vFile=''+'web-app/videos/'+f4vNamer
f4vF.transferTo( new File('web-app/videos/'+f4vNamer))
videoInstance.movFile=''+'web-app/videos/'+movNamer
movF.transferTo( new File('web-app/videos/'+movNamer))
videoInstance.gpFile=''+'web-app/videos/'+gpNamer
gpF.transferTo( new File('web-app/videos/'+gpNamer))
videoInstance.lightFile=''+'web-app/videos/'+lightNamer
lightF.transferTo( new File('web-app/videos/'+lightNamer))
}
videoInstance.validate()
if (videoInstance.hasErrors()) {
respond videoInstance.errors, view:'create'
return
}
videoInstance.save flush:true
request.withFormat {
form multipartForm {
flash.message = message(code: 'default.created.message', args: [message(code: 'video.label', default: 'Video'), videoInstance.title])
redirect videoInstance
}
'*' { respond videoInstance, [status: CREATED] }
}
}
I have set the grails.web.disable.multipart
to true
is there something simple that I am missing to make that method work.