1. #1
    Sencha User
    Join Date
    May 2012
    Posts
    15
    Vote Rating
    0
    lmcadory is on a distinguished road

      0  

    Default Unanswered: Using Spring MVC with fileupload field.

    Unanswered: Using Spring MVC with fileupload field.


    I'm having a problem getting the file object when I use FormPanel, FileUploadField, and Spring.


    Here is what I have:


    I added the CommonsMultipartResolver bean to my Spring Context file:


    Code:
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
           <property name="maxUploadSize" value="100000"/>
        </bean>
    I have a model class with the regular getters and setters:


    Code:
    pulic class UploadItem{
          private String filename;
          private CommonsMultipartFile fileData;
          ....
          getters/setters
          ....
        }
    My controller class:


    Code:
    @Controller
        @RequestMapping("/Foo")
        public class ThingController extends BaseController implements ServlerContextAware{
          ....
          @RequestMapping(value = "/bar", method = RequestMethod.POST)
          public @ResponseBody
          String createFile(UploadItem item, BindingResults results){
             String orgFile = item.getFileData().getOriginalFilename();
             return orgFile;
          }
    I'm using UiBinding to create the form fields, but I'm calling the fileupload field and formpanel to add the other methods in code.


    I have a submit button that calls:


    Code:
     form.submit();
    And my constructor I take care of the other form requirements:


    Code:
    form.setMethod(Method.POST);
          form.setEncoding(Encoding.MULTIPART);
          form.setAction("http://url.com/foo/bar");
          form.addSubmitCompleteHandler(new SubmitCompleteHandler(){
             @Override
             public void onSubmitComplete(SubmitCompleteEvent event){
                  String results = event.getResults();
                  Info.display("Upload Response", results);
             }
          });
    When I run the code I get a nullpointerexecption on item.getFileData().getOriginalFilename();


    I don't know what the problem is.

  2. #2
    Ext GWT Premium Member icfantv's Avatar
    Join Date
    Sep 2011
    Location
    Superior, CO
    Posts
    411
    Answers
    20
    Vote Rating
    21
    icfantv will become famous soon enough icfantv will become famous soon enough

      0  

    Default


    Do you know what part of that method chain is causing the NPE? I.e., is "item" or getFileData() the one returning null - both cases will cause an NPE.

    It's been a while since I did file uploads w/ Spring, is that maxFileSize in kb? Are you sure you're not exceeding this? (I can't remember, does this throw an exception when the file is too large?)

    Another thing to try is to remove Spring from the equation and simply set up your own HttpServlet to try and isolate where the issue may be.

Thread Participants: 1

Tags for this Thread