How to get MultipartRequest from Servlet3SecurityContextHolderAwareRequestWrapper

I am using Grails 2.4.3, and I have <g:uploadForm> with the method set for publishing, but I do not get MutlipartRequest in my controller action. Instead, I get Servlet3SecurityContextHolderAwareRequestWrapper , which does not have a getFile() method. I tried casting, I tried to get the request from the shell using request.request , and I tried a bunch of other things that, as I saw, I suggested to others with a similar problem, but still not cubes. I'm sure I missed something simple. I tend to do this, but if someone can point me in the right direction, I would be very grateful.

Here is 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 is 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 is the error I get:

URI / app / upload / uploadSupplemental Class groovy.lang.MissingMethodException Message No method signature: org.springframework.security.web.servletapi.HttpServlet3RequestFactory $ Servlet3SecurityContextHolderAwareRequestWrapper.getFile () values ​​are java Additional data] Possible solutions: getXML (), getPart (java.lang.String), getAt (java.lang.String), getAt (java.lang.String), getLocale (), getJSON ()

+7
spring-security upload grails
source share
2 answers

The following configuration property must 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 is the same exception.

Also make sure the user is authenticated (using @Secured ) before the download action.

+2
source share

I had the same error in my grails application and the following solution came out:

The request instance type in my application was associated with the content type attribute inside the HTTP message that reaches the server. So, if I had a file entry inside the form with the enctype attribute set to ...

 <form enctype="multipart/form-data" action="upload" method="POST"> 

... I got MutlipartRequest, as expected, and could get the downloaded file calling request.getFile() .

But if the HTTP message had the content type “application / octet-stream” (as, for example, when we load the Valu AJAX File-Uploader file to download one file), then the request itself is a binary file and can be converted to InputStream, calling request.getInputStream() .

So, if you are not sure what type of content is used in your application, I recommend checking it with a browser tool like firebug and trying request.getInputStream() to get the file directly from the request.

See differences between content type and enctype

0
source share

All Articles