0

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.

2
  • try multiple="" change to multiple Commented Aug 17, 2015 at 5:44
  • I have tried to change it to multiple or multiple="multiple" but it doesnt work Commented Aug 17, 2015 at 6:03

1 Answer 1

0

in jsp use following

<form ation="your/path" enctype="multipart/form-data" method="POST">

in controller use following

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

public String yourMethod(MultipartHttpServletRequest request){

}

this should resolve your problem

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.