grails 3.3.9从输入获取文件

时间:2019-02-12 14:16:44

标签: file grails

我目前在grails 3.3.9上遇到问题。 这是我的代码:

<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>

在我的Controlle中,我尝试过:

def file = params.myFile

但是我的文件为空。

并带有:

def file = request.getFile('myFile')
  

由于:groovy.lang.MissingMethodException:没有方法的签名:   net.bull.javamelody.JspWrapper $ HttpRequestWrapper3.getFile()是   适用于参数类型:(java.lang.String)值:[myFile]   可能的解决方案:getXML(),getPart(java.lang.String),   getAt(java.lang.String),getAt(java.lang.String),getLocale(),   getJSON()           在


上: 要提供更多信息,这是我的构建gradle。我想我必须添加一个特定的插件来处理文件上传。

我尝试过:编译'commons-fileupload:commons-fileupload:1.4'。但仍然存在相同的错误。我真的迷路了。有想法吗?

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 个答案:

答案 0 :(得分:1)

我能够找到为什么我无法上传任何文件的原因:在我的Resources.groovy文件中,我有:

let uploadId
let params = { Bucket: s3_bucket, Key: filename, ContentType: filetype }
s3.createMultipartUpload(params, (err, data) => {
    uploadId = data.uploadId
    console.log(uploadId)
    console.log("uploadId err: ", err)
})
return uploadId

此行阻止我上传所有文件。

相关问题