Grails 上传文件没有方法 getFile() 的签名 [英] Grails upload file no signature for method getFile()

查看:15
本文介绍了Grails 上传文件没有方法 getFile() 的签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在实现带有输入字段和文件上传的简单表单.我浏览了教程:http://grails.org/Simple+Avatar+Uploader和文档:http://grails.org/doc/2.0.x/指南/theWebLayer.html#uploadingFiles

I am implementing simple form with input fields and file upload. I went over tutorial: http://grails.org/Simple+Avatar+Uploader and documentation: http://grails.org/doc/2.0.x/guide/theWebLayer.html#uploadingFiles

然而文件上传似乎不起作用!为什么它不起作用?问题有什么解决方案吗?

However file upload doesn't seem to work! Why is it not working? Any solutions for the problem?

问题:

没有方法签名:org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper.getFile()适用于参数类型:(java.lang.String) 值:[itemImage] 可能的解决方案:getXML()、getPart(java.lang.String)、getAt(java.lang.String), getAt(java.lang.String), getLocale(),getJSON().堆栈跟踪如下: 消息:没有方法签名:org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper.getFile()适用于参数类型:(java.lang.String) 值:[itemImage] 可能的解决方案:getXML()、getPart(java.lang.String)、getAt(java.lang.String), getAt(java.lang.String), getLocale(),getJSON() 行 |方法->> 14 |保存在 greatoffer.SellController$$EOVmPG4d- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |195 |grails.plugin.cache.web.filter.PageFragmentCachingFilter 中的 doFilter |63 |grails.plugin.cache.web.filter.AbstractFilter 中的 doFilter |53 |过滤grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter|49 |过滤grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter|82 |过滤grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter|第895话java.util.concurrent.ThreadPoolExecutor$Worker 中的 runTask |918 |运行在 '' ^ 662 |跑 ..在 java.lang.Thread

No signature of method: org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper.getFile() is applicable for argument types: (java.lang.String) values: [itemImage] Possible solutions: getXML(), getPart(java.lang.String), getAt(java.lang.String), getAt(java.lang.String), getLocale(), getJSON(). Stacktrace follows: Message: No signature of method: org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper.getFile() is applicable for argument types: (java.lang.String) values: [itemImage] Possible solutions: getXML(), getPart(java.lang.String), getAt(java.lang.String), getAt(java.lang.String), getLocale(), getJSON() Line | Method ->> 14 | save in greatoffer.SellController$$EOVmPG4d - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | 195 | doFilter in grails.plugin.cache.web.filter.PageFragmentCachingFilter | 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter | 53 | doFilter in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter | 49 | doFilter in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter | 82 | doFilter in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter | 895 | runTask in java.util.concurrent.ThreadPoolExecutor$Worker | 918 | run in '' ^ 662 | run . . in java.lang.Thread

主要 GSP:

<g:uploadForm action="save" method="POST">
    <fieldset class="form">
        <g:render template="form"/>
    </fieldset>
    <fieldset class="buttons">
        <g:submitButton name="create" class="save" value="${message(code: 'default.button.create.label', default: 'Create')}" />
    </fieldset>
</g:uploadForm>

表格 GSP 的图片上传部分:

Image Upload part of the Form GSP:

<label for="images">
    <g:message code="item.images.label" default="Images" />
</label>

<input type="file" name="itemImage" />

控制器:

import grails.plugin.springsecurity.annotation.Secured

@Secured('permitAll')
class SellController {

    def index() {
        render(view: "seller")
    }

    def save() {
        println "Here are params: ${params}";
        def f = request.getFile('itemImage')
        flash.message = message(code: 'default.created.message', args: [message(code: 'item.label', default: 'Item'), params.id])
        render(view: "seller")
    }
}

推荐答案

根据堆栈跟踪中的类型,Spring Security @Secured 批注将您的请求包装在 SecurityContextHolderAwareRequestWrapper.您需要访问 MultipartHttpServletRequest 调用 getFile 我相信.

By the type in your stack trace, the Spring Security @Secured annotation is wrapping your request in a SecurityContextHolderAwareRequestWrapper. You need to get at the MultipartHttpServletRequest to call getFile I believe.

此外,在您的调试中,这里有 params 语句,您看到 itemImage 了吗?如果是这样,我实际上认为这可能很容易.

Also, in your debug Here are params statement, are you seeing the itemImage? If so, I actually think it might be this easy.

def file = params.itemImage

更新:我对评论投了赞成票.当我开始打字时,他们不在.

UPDATE: I upvoted the comments. They weren't there when I started typing.

这篇关于Grails 上传文件没有方法 getFile() 的签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆