简体   繁体   中英

Error while uploading file in 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.

The error is

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

please help me.

[ Edit - disregard this as per Burt's comment. It would only work in Java/Spring]

You might have to cast your request object to the usual MultipartHttpServletRequest :

MultipartHttpServletRequest mhsr = (MultipartHttpServletRequest) request
MultipartFile file = mhsr.getFile("attachments")

As Spring security appears to be injecting its own Servlet3SecurityContextHolderAwareRequestWrapper version of request , I'm guessing.

为此存在Jira问题,只需在配置文件中设置grails.web.disable.multipart=true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM