Mikhail
Mikhail

Reputation: 87

Grails upload file Exception, caused by springsecurity

I work with grails 1.3.7 and i have a strange bug. This is my code for uploading 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 all works perfectly, but in production mode I have thiw 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 tryied this code:

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

But it isn`t work too.

I use sprigsecurity-core1.2 and grails 1.3.7/ I cant`t upgrade this.

Thanks you for any response

Upvotes: 3

Views: 265

Answers (1)

Tim Shier
Tim Shier

Reputation: 11

Thanks for this - 4 years later and you just saved me. In your code, the issue seems to be that you're casting request to a MultipartHttpServletRequest but then you're not setting uploadAvatar to this cast version of request (mpr). Try changing your last line of code to:

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

Thanks for the help!

Upvotes: 1

Related Questions