I am trying to upload multiple files using html5 attribute multiple. This link provide me a good start. However, I am facing a problem that I am not be able to read multipartFile in my controller.
Here is my POjO class
public class FileProduct {
private String name;
private List<MultipartFile> images;
}
My Controller
public String processNewListing(Model model
, @ModelAttribute FileProduct product
, HttpServletRequest request
) {
List<MultipartFile> files = product.getImages();
List<String> fileNames = new ArrayList<String>();
log.info("Files legnth: " + files.size());
log.info("name: " + product.getName());
}
And this if my form:
<form:form commandName="product" action="${newListingForm }" method="POST" enctype="multipart/form-data">
<form:input path="name" type="text"/>
<form:input path="images" type="file" multiple=""/>
<input type="submit">
</form:form>
So I am able to print out the "name" in my controller but my "files" is always has size of 1 regardless I have selected any file or not. I have followed the suggestion in the link to include common-fileupload and common-io, but the problem is not fix.
multiple=""change tomultiple