Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MultipartFile-array property [SPR-2784] #7471

Closed
spring-projects-issues opened this issue Oct 31, 2006 · 11 comments
Closed

Support MultipartFile-array property [SPR-2784] #7471

spring-projects-issues opened this issue Oct 31, 2006 · 11 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Oct 31, 2006

Maarten Winkels opened SPR-2784 and commented

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.


Affects: 2.0 final

Attachments:

Issue Links:

Referenced from: commits 255d1ad, 66a7995, b2b1ff6, 9b3fbc2

7 votes, 12 watchers

@spring-projects-issues
Copy link
Collaborator Author

Maarten Winkels commented

The attached patch implements this improvement for commons-upload. It seems that COS doesn't support file parts with the same name, thus the feature cannot be implemented there.

@spring-projects-issues
Copy link
Collaborator Author

John David Dunlap commented

As I understand it, COS support was removed from Spring in 2.5. That being the case, would it be possible to get this implemented?

@spring-projects-issues
Copy link
Collaborator Author

Cameron McEwing commented

Hi There, Love to see this one fixed, as it limits the ability to do multiple flie multipart uploads from Adobe Flex. Yes their are some workarounds ... http://dhruba.name/2008/12/27/implementing-single-and-multiple-file-multipart-uploads-using-spring-25/ . But we really shouldn't need these. Cheers Cameron

@spring-projects-issues
Copy link
Collaborator Author

Arjen Poutsma commented

Fixed. The MultipartRequest now has a List<MultipartFile> getFiles(String) method, as well as a MultiValueMap<String, MultipartFile> getMultiFileMap() method.

@spring-projects-issues
Copy link
Collaborator Author

Jonathan Nuñez Aguin commented

bindMultipartFiles is not using the news methods getFiles(String) and getMultiFileMap(), in this way the property "aFileArray" is not bound correctly.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Reopened for revisiting DataBinder's MultipartFile support.

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Jonathan Nuñez Aguin commented

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.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

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

Juergen

@spring-projects-issues
Copy link
Collaborator Author

Laurent Bois commented

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

@spring-projects-issues
Copy link
Collaborator Author

Laurent Bois commented

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

@spring-projects-issues
Copy link
Collaborator Author

Stevo Slavić commented

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants