0
votes

I'm having currently a problem with grails 3.3.9. Here is my code:

<g:uploadForm resource="${objetInstance}"role="form" method="POST" class="form-horizontal">

  <g:actionSubmit action="update" class="btn green-meadow"
    value="${message(code: 'enregistrer', 'default': 'Enregistrer')}"/>

               <input type="file" name="myFile" id="myFile"
                               class="form-control"
                               value=""/>

 </g:uploadForm>

and in my Controlle, I tried:

def file = params.myFile

but my file is null.

And with:

def file = request.getFile('myFile')

Caused by: groovy.lang.MissingMethodException: No signature of method: net.bull.javamelody.JspWrapper$HttpRequestWrapper3.getFile() is applicable for argument types: (java.lang.String) values: [myFile] Possible solutions: getXML(), getPart(java.lang.String), getAt(java.lang.String), getAt(java.lang.String), getLocale(), getJSON() at


Up: To provide more info, here is my build gradle. I think I have to add a specific plugin to handle file upload.

I tried: compile 'commons-fileupload:commons-fileupload:1.4'. but still having the same error. I am really lost. Any idea?

buildscript {
    repositories {
        mavenLocal()
        maven { url "https://repo.grails.org/grails/core" }
        maven { url "https://mvnrepository.com/artifact" }
        maven { url "https://mvnrepository.com/artifact/org.keycloak/keycloak-spring-security-adapter" }
        maven { url "https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging" }
    }
    dependencies {
        classpath "org.grails:grails-gradle-plugin:$grailsVersion"
        classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.15.1"
        classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
        classpath 'net.saliman:gradle-cobertura-plugin:2.5.4'
        classpath "org.grails.plugins:views-gradle:1.2.8"
    }
}

version "4.0.0_RC20"
group "myProject"

apply plugin: "eclipse"
apply plugin: "idea"
apply plugin: "war"
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
apply plugin: "asset-pipeline"
apply plugin: "net.saliman.cobertura"
apply plugin: "org.grails.plugins.views-json"
apply from: "gradle/sonar.gradle"

repositories {
    mavenLocal()
    maven { url "https://repo.grails.org/grails/core" }
    maven { url "https://mvnrepository.com/artifact" }
    maven { url "http://dl.bintray.com/dmahapatro/plugins" }
}

dependencies {

    compile "com.warrenstrange:googleauth:1.1.2"
    compile "com.google.zxing:core:3.3.1"
    compile "com.google.zxing:javase:3.3.1"
    compile 'org.grails.plugins:grails-spring-websocket:2.4.1'

    compile "org.springframework.boot:spring-boot-starter-logging"
    compile "org.springframework.boot:spring-boot-autoconfigure"
    compile "org.grails:grails-core"
    compile "org.springframework.boot:spring-boot-starter-actuator"
    compile "org.springframework.boot:spring-boot-starter-tomcat"
    compile "org.grails:grails-dependencies"
    compile "org.grails:grails-web-boot"
    compile "org.grails.plugins:cache"
    compile "org.grails.plugins:scaffolding"
    compile "org.grails.plugins:hibernate5"
    compile "org.hibernate:hibernate-core:5.1.16.Final"
    compile "org.hibernate:hibernate-ehcache:5.1.16.Final"

    testCompile "org.grails:grails-datastore-gorm-test:$gormVersion"
    console "org.grails:grails-console"
    profile "org.grails.profiles:web"
    runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.15.1"
    runtime "com.h2database:h2"
    testCompile "org.grails:grails-plugin-testing"
    testCompile "org.grails.plugins:geb"
    testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
    testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"

    runtime 'org.apache.tomcat:tomcat-jdbc'

    compile 'org.grails:grails-logging'

    //postgresql
    provided 'org.postgresql:postgresql:9.4.1211'

    // Build Test Data
    compile "org.grails.plugins:build-test-data:3.3.1"

    // Audit Logging
    compile "org.grails.plugins:audit-logging:3.0.1"

    // Quartz
    compile "org.grails.plugins:quartz:2.0.13"

    // Phone Numbers
    compile 'ca.redtoad:grails-phonenumbers:0.11'

    // Rest Client
    compile 'org.grails:grails-datastore-rest-client'

    // Jasper
    compile "org.grails.plugins:jasper:2.1.0.RC1"

    //excel import
    compile 'org.grails.plugins:excel-import:3.0.2'

    //Quartz monitor
    compile ('org.grails.plugins:quartz-monitor:1.3'){
        exclude group: 'org.grails.plugins', module: 'asset-pipeline'
    }

    compile group: 'com.google.code.gson', name: 'gson', version: '2.8.5'

    compile "org.grails.plugins:views-json:1.2.8"

    //ajout des dependances de keycloak
    compile "org.keycloak:keycloak-spring-security-adapter:3.0.0.Final"
    runtime "org.jboss.logging:jboss-logging:3.3.0.Final"

     //File upload
    compile 'commons-fileupload:commons-fileupload:1.4'

    // Include external jars
    compile fileTree(dir: 'libs', include: '*.jar')

    // pour les tests
    testCompile "org.grails:grails-test-mixins:3.3.0"
    testCompile "org.grails:grails-gorm-testing-support:1.1.5"
    testCompile "org.grails:grails-web-testing-support:1.1.5"
}

bootRun {
    jvmArgs('-Dspring.output.ansi.enabled=always')
    addResources = true
}

integrationTest {
    testLogging {
        exceptionFormat = 'full'
        events 'failed', 'standardOut', 'standardError'
    }
    beforeTest { descriptor ->
        logger.quiet " -- $descriptor"
    }
}

assets {
    minifyJs = true
    minifyCss = true
    packagePlugin = true
    includes = ["metronic_v4_7_1_admin_3_rounded/*"]
}

cobertura {
    coverageFormats = ['xml', 'html']
}

test.finalizedBy(project.tasks.cobertura)
1
Thanx @JeffScottBrown. I already checked but nothing helpful to me for now. By the way I upgraded my grails version from grails 3.2.9 to last version of grails. Since then, I cannot get a file from the field input type file. I really don't undestand why because it should still works. - Coumbiss
Looks like you're using melody in your project? Could you disable that to check if it's causing the problem? It should provide the getFile() method for you (or pass it through appropriately) but perhaps it is not. - Daniel
@Daniel sorry for the delay. I disable melody. I still have an error but now it's: org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper.getFile() is applicable for argument types: (java.lang.String). - Coumbiss
Because I am using keyCloak, I think it's linked to keyCloak Spring security filters. Any idea? - Coumbiss

1 Answers

1
votes

I was able to find why I couldn't upload any files: In my file Resources.groovy, I had :

import org.springframework.web.filter.RequestContextFilter

beans{
    ...
    requestContextFilter(RequestContextFilter)
}

This line was preventing me from uploading all files.