My Code In gsp:
<html>
<body>
<g:form controller="some_controller" action="some_action" enctype="multipart/form-data">
<input id="Resume" type="file" name="Resume" />
</g:form>
</body>
</html>
My controller code :
def candidate = new Candidate(params)
MultipartHttpServletRequest mhsr = (MultipartHttpServletRequest) request
MultipartFile candResume = mhsr.getFile('candResume')
if(userService.fileExt().contains(candResume.getContentType()))
{
candidate.candResume=candResume.getBytes() //Converting a file into bytes
if(candidate.validate())
{
if(candidate.save(flush: true,failOnError: true))
{
println "++++++++++Candidate Success+++++++++++++"
flash.candSuccess="Candidate successfully added."
}
}
else{
println "====Sorry Candidate Upload Failed===="
flash.candFail="Candidate failure."
}
}
My service code :
public List fileExt(){
List fileExtensions=["doc", "docx", "pdf", "rtf"]
println "--------in the service----------"
return fileExtensions
}
The thing is in if(userService.fileExt().contains(candResume.getContentType())) the service is getting invoked but not retiurning anything the upload is getting failed without any message. Please help. Thanks in advance.