如何从 Servlet3SecurityContextHolderAwareRequestWrapper 中获取 MultipartRequest [英] How do I get a MultipartRequest out of a Servlet3SecurityContextHolderAwareRequestWrapper

查看:33
本文介绍了如何从 Servlet3SecurityContextHolderAwareRequestWrapper 中获取 MultipartRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Grails 2.4.3 并且我有一个 <g:uploadForm> 方法设置为 post,但我没有收到 MutlipartRequest我的控制器动作.相反,我得到了一个没有 getFile() 方法的 Servlet3SecurityContextHolderAwareRequestWrapper.我试过强制转换,我试过用 request.request 从包装器中取出请求,我试过很多其他的东西,我见过的其他人有类似的问题,但仍然没有骰子.我确定我错过了一些简单的东西.我倾向于这样做,但如果有人能指出我正确的方向,我将不胜感激.

这是我的表格:

 

<div class="modal-body"><label for="fileInput">选择要上传的文件:</label><input type="file" id="fileInput" name="supplementalData"/>

<div class="modal-footer"><button type="button" class="btn btn-default" data-dismiss="modal">取消</button><input type="submit" class="btn btn-primary"/>

</g:uploadForm>

这是我的控制器操作:

 def uploadSupplemental() {MultipartRequest multipartRequest = 请求为 MultipartRequestdef file = multipartRequest.getFile('supplementalData')如果(文件){flash.message = "找到文件!!"} 别的 {flash.message = "文件未找到.:-( "}重定向操作:'list'}

这是我得到的错误:

<块引用>

URI/app/upload/uploadSupplemental 类groovy.lang.MissingMethodException 消息 没有方法签名:org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper.getFile()适用于参数类型:(java.lang.String) 值:[supplementalData] 可能的解决方案:getXML(),getPart(java.lang.String), getAt(java.lang.String),getAt(java.lang.String), getLocale(), getJSON()

解决方案

为了启用 multipart,必须在 Config.groovy 中将以下配置属性设置为 true请求.

grails.web.disable.multipart=true

这是一个相关的JIRA问题SO 中的重复问题 报告相同的异常.

还要确保用户在上传操作之前已通过身份验证(使用 @Secured).

I'm using Grails 2.4.3 and I have a <g:uploadForm> with method set to post, but I'm not getting a MutlipartRequest in my controller action. Instead I'm getting a Servlet3SecurityContextHolderAwareRequestWrapper which has not getFile() method. I've tried casting, I've tried getting the request out of the wrapper with request.request, and I've tried a bunch of other things I've seen suggested to others with a similar problem, but still no dice. I'm sure I'm missing something simple. I tend to do that, but if anyone can point me in the right direction, I'd be very grateful.

Here's my form:

  <g:uploadForm method="POST" action="uploadSupplemental" >
    <div class="modal-header">
      <h3 class="modal-title" id="myModalLabel">Upload Supplemental Data File</h3>
    </div>
    <div class="modal-body">
      <label for="fileInput">Choose file to upload:</label>
      <input type="file" id="fileInput" name="supplementalData" />
    </div>
    <div class="modal-footer">
      <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
      <input type="submit" class="btn btn-primary" />
    </div>
  </g:uploadForm>

And here's my controller action:

  def uploadSupplemental() {
    MultipartRequest multipartRequest =  request as MultipartRequest
    def file = multipartRequest.getFile('supplementalData')
    if (file){
      flash.message = "File found!!"
    } else {
      flash.message = "File NOT found.  :-( "
    }
    redirect action:'list'
  }

And here's the error I get:

URI /app/upload/uploadSupplemental Class groovy.lang.MissingMethodException Message No signature of method: org.springframework.security.web.servletapi.HttpServlet3RequestFactory$Servlet3SecurityContextHolderAwareRequestWrapper.getFile() is applicable for argument types: (java.lang.String) values: [supplementalData] Possible solutions: getXML(), getPart(java.lang.String), getAt(java.lang.String), getAt(java.lang.String), getLocale(), getJSON()

解决方案

The following config property has to be set to true in Config.groovy in order to enable multipart requests.

grails.web.disable.multipart=true

Here is a related JIRA issue and a duplicate question in SO reporting the same exception.

Also make sure the user is authenticated (with @Secured) before the upload action.

这篇关于如何从 Servlet3SecurityContextHolderAwareRequestWrapper 中获取 MultipartRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
其他开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆