Announcement Announcement Module
No announcement yet.
HTML5 multiple file upload & Spring MVC Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • HTML5 multiple file upload & Spring MVC

    I'm attempting to use HTML5 input type=file multiple and attempting to upload multiple files using spring (3.x) mvc. Anyone have any idea in doing this? I've attempted to use the apache commons IO, but to no avail. I've also attempted to use the spring multipart resolver as well, but to no avail. the FileItems object is always null. Anyone have any idea on how to go about doing this? There's not much document out there about this. If I can implement I'd like to post my code on the web to show how it can be done, so any help is greatly appreciated!!


  • #2
    Solution - HTML5 Multiple file upload

    Hey all:
    I was able to figure this out if anyone is interested. It turns out it is pretty straight forward to do. I wasn't using the MultiHttpServletRequets correctly.

    Here is the code of the method that is used to process the uploaded files (note: this is just test code that I've been playing around with so it needs some fixing, but it'll get you up and running):

    	public ModelAndView upload(HttpServletRequest request, HttpServletResponse response) throws Exception {
    		    MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;	
    		    MultiValueMap<String, MultipartFile> map = multipartRequest.getMultiFileMap();
    				if(map != null) {
    					Iterator iter = map.keySet().iterator();
    					while(iter.hasNext()) {
    						String str = (String);
    						List<MultipartFile> fileList =  map.get(str);
    						for(MultipartFile mpf : fileList) {
    							File localFile = new File("c:\\temp\\" + StringUtils.trimAllWhitespace(mpf.getOriginalFilename()));
    							OutputStream out = new FileOutputStream(localFile);
    		        return null;


    • #3
      This does indeed solve the multiple file "issue", but still I'm having a hard time implementing this because my chunks keep on overwriting the same file instead of appending to it.

      I could think of ways to fix this by appending the different calls.

      But I'm a afraid things might get nasty when multiple people are uploading simultaneously and the chunks don't nicely follow each other.

      Any thoughts on how to solve this perhaps?


      EDIT: SOLVED! (kinda)

      I was using for the uploads, and the flash version is preferred above the HTML5 version by default.
      Though the different parts were not automatically stiched together somehow.
      Switching the preference of HTML5 above Flash did solve my issue.

      Pehaps this might be useful for someone having the same nightmare sometime...
      Last edited by Dr.Drane; Feb 12th, 2011, 07:28 AM.