本文介绍了在Grails 2.3.7中上传文件时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将在发送电子邮件时附加文件.
I am going to attach a file when send the email.
<g:formRemote id="emailWidgetForm" name="emailOrderMailForm" enctype="multipart/form-data"
on404="alert('not found!')"
onLoading="showSpinner('emailWidget');" onComplete="hideSpinner();"
url="[controller: 'emailSender', action:'sendPersonalEmailToCustomer']"
action="${createLink(controller: 'emailOrder', action:
'sendPersonalEmailToCustomer')}"
before="if( validateGivenForm( 'emailWidgetForm' ) ) { " after="}">
<tr>
<td><strong>Attachment</strong></td>
<td><input type="file" size="10" name="attachments"/></td>
</tr>
<g:submitButton name="sendEmailButton" class="btn btn-primary pull-right"
value="Send Email"/>
</g:formRemote>
当我要像这样在控制器中使用它
When I am going to get this in controler like
def file = request.getFile('attachments');
我在上面的这一行中遇到了错误.
I am getting Error on this above line.
错误是
groovy.lang.MissingMethodException: No signature of method:
org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper.getFile() is applicable for argument types: (java.lang.String) values: [attachments]
Possible solutions: getXML(), getPart(java.lang.String), getAt(java.lang.String), getAt(java.lang.String), getLocale(), getJSON()
请帮助我.
推荐答案
[编辑-根据Burt的评论忽略此内容.它仅适用于Java/Spring]
[Edit - disregard this as per Burt's comment. It would only work in Java/Spring]
您可能必须将request
对象转换为通常的MultipartHttpServletRequest
:
You might have to cast your request
object to the usual MultipartHttpServletRequest
:
MultipartHttpServletRequest mhsr = (MultipartHttpServletRequest) request
MultipartFile file = mhsr.getFile("attachments")
我猜测,由于Spring安全性似乎正在注入其自己的Servlet3SecurityContextHolderAwareRequestWrapper
版本的request
.
As Spring security appears to be injecting its own Servlet3SecurityContextHolderAwareRequestWrapper
version of request
, I'm guessing.
这篇关于在Grails 2.3.7中上传文件时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!