Exception from Grails file thrown by springsecurity

I am working with grails 1.3.7 and I am having a strange error. This is my code to download the file:

def editAvatar = {
            def uploadedAvatar = request.getFile("uploadedAvatar");
    if(!uploadedAvatar?.isEmpty()) {
        clientService.saveUploadedAvatar(uploadedAvatar, basePath);
        render 'avaterUdated';
    } else {
        render(contentType:"text/json", encoding:"UTF-8") {
            [valid:false, error: "some error"]
        }
    }

      

In development environment everything works fine, but in production mode I have an exception:

org.codehaus.groovy.runtime.typehandling.GroovyCastException: 
 Cannot cast object 'org.springframework.security.web.firewall.RequestWrapper@1ce4ded'with class 'org.springframework.security.web.firewall.RequestWrapper' to class 'org.springframework.web.multipart.MultipartHttpServletRequest'
at ru.pscb.web.grb.ui.UserProfileController$_closure6.doCall(UserProfileController.groovy:80)

      

I also tried using this code:

MultipartHttpServletRequest mpr = (MultipartHttpServletRequest)request;
    def uploadedAvatar = request.getFile("uploadedAvatar");

      

But that doesn't work either.

I am using sprigsecurity-core1.2 and grails 1.3.7 / I cannot update this.

Thanks for any answer

+3


source to share


1 answer


Thank you for that - 4 years later and you just saved me. In your code, the problem is that you are sending a request to MultipartHttpServletRequest

, but then you are not setting the uploadAvatar for that version of the request (mpr). Try changing your last line of code to:

def uploadedAvatar = mpr.getFile("uploadedAvatar");

      



Thanks for the help!

+1


source







All Articles