Sukumar Karuppusamy
Sukumar Karuppusamy

Reputation: 21

request parameters null for file upload greater than 150kb with multipartfile upload, Spring 3.2, wildfly 9.0.0

We upgraded the code from jboss 4 to wildfly 9 and upgraded spring 2.5 to spring 3.0 and everything is working good.

While we are uploading files less than 150kb using MultipartFile, it is working fine. but when file size exceeds 150kb all request parameters and multipartfile becomes null.

We are using Spring 3.2, java 8, wildfly 9.0

i am attaching my code for your reference

Controller

@Controller
@MultipartConfig(fileSizeThreshold=1024*1024*2, // 2MB
maxFileSize=1024*1024*10,      // 10MB
maxRequestSize=1024*1024*50)
public class MyPortFolioController{

@RequestMapping(value = UrlPrefix.consumer+"/myportfolio.htm", method = RequestMethod.POST)
    public ModelAndView uploadFile(@ModelAttribute Portfolio portfolio, BindingResult result, 
            Model model,@RequestParam("file")MultipartFile f,HttpServletRequest request,HttpServletResponse response, HttpSession session

jsp file

    <form:form modelAttribute="portfolio" method="POST" id="myuplod" enctype="multipart/form-data" name="portfolioform">

<form:select path="protfolioTypeIdentifier" id="selectType" cssClass="form-control" cssStyle="width:auto;">
                                      <form:option value="0">Select one</form:option>
                                      <form:options items="${portfolioType}"
                                            itemValue="protfolioTypeIdentifier"
                                            itemLabel="portFolioTypeName" />
                                  </form:select>
<input type="file" name="file" class="btn btn-primary" onchange="dwr.util.byId('upportf').style.display='block';"/>
<input  type="submit" value="Upload" class="btn btn-warning" id="upportf" name="Upload" onclick="displayLoaderScreen();"/>

</form:form>

applicationContext.xml

<bean id="multipartResolvder" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" >
    <!-- 25 mb max -->
     <property name="maxUploadSize" value="26214400"/>
</bean>

please help

Upvotes: 2

Views: 619

Answers (1)

Abhijit Chowdhury
Abhijit Chowdhury

Reputation: 222

Files with size "maxInMemorySize " are stored in memory, otherwise they will be stored in disk directly. Default is 10KB (10240 bytes)

Add these line in spring.xml Add these line in spring.xml

    <!-- mutipart upload configuration -->
    <bean id="multipartResolver"
        class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <!-- max upload size in bytes 2MB-->
        <property name="maxUploadSize" value="2097152" />
        <!-- max size of file in memory (in bytes) 2MB -->
        <property name="maxInMemorySize" value="2097152" />
    </bean>

Upvotes: 1

Related Questions