Announcement Announcement Module
Collapse
No announcement yet.
Multipart File and MultiActionController Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Multipart File and MultiActionController

    Hi there,

    I've tried to get the automagical conversion of upload file contents to a string by doing this in my MultiActionController:

    Code:
      protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws ServletException {
        binder.registerCustomEditor(String.class, new StringMultipartFileEditor());
      }
    but it wouldn't work, gave me a conversion error. Is there a reason why the multiaction controller can't support this?

    I implemented the following:
    Code:
    public class UploadBean {
      private org.springframework.web.multipart.commons.CommonsMultipartFile uploadFileContents;
    
      public org.springframework.web.multipart.commons.CommonsMultipartFile getUploadFileContents() {
        return uploadFileContents;
      }
    
      public void setUploadFileContents(org.springframework.web.multipart.commons.CommonsMultipartFile uploadFileContents) {
        this.uploadFileContents = uploadFileContents;
      }
    }
    and then use the three parameter version of my request method:
    Code:
      public ModelAndView saveAndValidate(HttpServletRequest request, HttpServletResponse response, UploadBean ub) 
        throws Exception 
      {
    and then use the following to get my string:
    Code:
    new String(ub.getUploadFileContents().getBytes());
    I present this as a working solution for the multiaction controller, but if anyone could tell me why this wasn't built in or if there is a problem that I'm not aware of that would be great.

    Thanks in advance,

    Mark
Working...
X