gpt4 book ai didi

Grails 上传文件没有 getFile() 方法的签名

转载 作者:行者123 更新时间:2023-12-02 09:53:05 25 4
gpt4 key购买 nike

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

但是文件上传似乎不起作用!为什么它不起作用?有什么解决办法吗?

问题:

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

主要普惠制:

<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 表格的图片上传部分:

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

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

Controller :

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 。

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

def file = params.itemImage

更新:我对评论投了赞成票。当我开始打字时他们还不在那里。

关于Grails 上传文件没有 getFile() 方法的签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21764419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com