Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 2.0 final
    • Fix Version/s: 3.0.4
    • Component/s: Web
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      When posting multiple non-file form fields with the same name, the CommonsMultipartResolver(as CommonsFileUploadSupport ) recognizes this as an array property. When posting multiple file form fields with the same name, the property value is overwritten. If the same logic would be applied, a bean could be populated with a MulitpartFile[] property.

      exmaple:

      public class Bean {
      private String aString;
      private String[] aStringArray;
      private MultipartFile aFile;
      private MulitpartFile[] aFileArray;
      }

      <form>
      <input name="aString" type="text"/>
      <input name="aStringArray" type="text"/>
      <input name="aStringArray" type="text"/>
      <input name="aFile" type="file"/>
      <input name="aFileArray" type="file"/>
      <input name="aFileArray" type="file"/>
      </form>

      if this forms is processed with the CommonsMultipartResolver, the String and String[] properties will be populated correctly (containing the two values in he array), the MultipartFile property will be filled correctly, but the MultipartFile[] property will contain only the last file.

      1. patch.txt
        6 kB
        Maarten Winkels

        Issue Links

          Activity

          Hide
          Jonathan Nuñez Aguin added a comment -

          If someone wants to check this error:

          public class Bean

          {MulitpartFile[] aFileArray;}

          <form>
          <input name="aFileArray" type="file" multiple="multiple"/>
          </form>

          This only fill the first file.

          Show
          Jonathan Nuñez Aguin added a comment - If someone wants to check this error: public class Bean {MulitpartFile[] aFileArray;} <form> <input name="aFileArray" type="file" multiple="multiple"/> </form> This only fill the first file.
          Hide
          Juergen Hoeller added a comment -

          Finally fixed for 3.0.4: WebDataBinder and @MVC request params detect and introspect MultipartFile arrays as well.

          Juergen

          Show
          Juergen Hoeller added a comment - Finally fixed for 3.0.4: WebDataBinder and @MVC request params detect and introspect MultipartFile arrays as well. Juergen
          Hide
          Laurent Bois added a comment -

          Hi

          I recently downloaded Spring 3.0.4 from http://www.springsource.com/download/community?sid=723222
          Upgraded my project

          And i need to do multi file upload in a spring webflow

          I tried
          public class MultipartFileHandler {

          MultipartFile[] files;

          public void setFiles(MultipartFile[] files)

          { this.files = files; }

          public MultipartFile[] getFiles()

          { return files; }

          public MultiPartFileUploadHandler processFiles() {
          if (files != null && files.length > 0) {
          for (int i = 0 ; i < files.length; i++ )

          { System.out.println("============= " + i + " ============="); System.out.println(" Processing file " + files[i].getOriginalFilename() + " / " + files[i].getContentType() ); }

          }
          }
          }

          In the HTML form :

          <form:form modelAttribute="fileUploadHandler" method="post" enctype="multipart/form-data">

          <p>Type: <input type="hidden" name="type" value="genericFileMulti" size="60" /></p>
          <p>File (Use CTRL Click to select multiple files): <input type="file" name="files" multiple="" /></p>
          </form:form>

          I use the tip for Firefox 3.6
          <input type="file" multiple=""/>

          src http://hacks.mozilla.org/2009/12/multiple-file-input-in-firefox-3-6/

          But this doesn't work on server side (method processFiles from the Model above MultipartFileHandler)... i only get the first file from the selected files chosen in the file picker from the HTML form

          Thanks for your help

          Show
          Laurent Bois added a comment - Hi I recently downloaded Spring 3.0.4 from http://www.springsource.com/download/community?sid=723222 Upgraded my project And i need to do multi file upload in a spring webflow I tried public class MultipartFileHandler { MultipartFile[] files; public void setFiles(MultipartFile[] files) { this.files = files; } public MultipartFile[] getFiles() { return files; } public MultiPartFileUploadHandler processFiles() { if (files != null && files.length > 0) { for (int i = 0 ; i < files.length; i++ ) { System.out.println("============= " + i + " ============="); System.out.println(" Processing file " + files[i].getOriginalFilename() + " / " + files[i].getContentType() ); } } } } In the HTML form : <form:form modelAttribute="fileUploadHandler" method="post" enctype="multipart/form-data"> <p>Type: <input type="hidden" name="type" value="genericFileMulti" size="60" /></p> <p>File (Use CTRL Click to select multiple files): <input type="file" name="files" multiple="" /></p> </form:form> I use the tip for Firefox 3.6 <input type="file" multiple=""/> src http://hacks.mozilla.org/2009/12/multiple-file-input-in-firefox-3-6/ But this doesn't work on server side (method processFiles from the Model above MultipartFileHandler)... i only get the first file from the selected files chosen in the file picker from the HTML form Thanks for your help
          Hide
          Laurent Bois added a comment -

          I also changed the HTML form, cf beginning of this thread.

          <form:form modelAttribute="fileUploadHandler" method="post" enctype="multipart/form-data">
          <p>File (2): <input type="file" name="files" size="60" /></p>
          <p>File (3): <input type="file" name="files" size="60" /></p>

          </form:form>

          Stil have the problem ...only the first file of the list is handled.

          Laurent

          Show
          Laurent Bois added a comment - I also changed the HTML form, cf beginning of this thread. <form:form modelAttribute="fileUploadHandler" method="post" enctype="multipart/form-data"> <p>File (2): <input type="file" name="files" size="60" /></p> <p>File (3): <input type="file" name="files" size="60" /></p> </form:form> Stil have the problem ...only the first file of the list is handled. Laurent
          Hide
          Stevo Slavić added a comment -

          I've just created improvement request SWF-1422, to have this same feature available in Spring Webflow - anyone interested, please vote for that ticket.

          I wonder why haven't "MultipartFile getFile(String name)" and "Map<String, MultipartFile> getFileMap()" methods in org.springframework.web.multipart.MultipartRequest been at least marked as deprecated if not removed, since getFiles and getMultiFileMap seem to cover well both case with single and multiple MultipartFile values per request parameter name.

          Show
          Stevo Slavić added a comment - I've just created improvement request SWF-1422 , to have this same feature available in Spring Webflow - anyone interested, please vote for that ticket. I wonder why haven't "MultipartFile getFile(String name)" and "Map<String, MultipartFile> getFileMap()" methods in org.springframework.web.multipart.MultipartRequest been at least marked as deprecated if not removed, since getFiles and getMultiFileMap seem to cover well both case with single and multiple MultipartFile values per request parameter name.

            People

            • Assignee:
              Juergen Hoeller
              Reporter:
              Maarten Winkels
              Last updater:
              Trevor Marshall
            • Votes:
              7 Vote for this issue
              Watchers:
              12 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                3 years, 23 weeks ago

                Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0d
                0d
                Logged:
                Time Spent - 1d 2.45h
                1d 2.45h