Question

I have an application in which files can be uploaded into the application using MultiPartRequest or DWR.

I have the following configuration.

Web.xml

<servlet>
    <servlet-name>nerp</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>fileUploadMaxBytes</param-name>
        <param-value>5000</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>nerp</servlet-name>
    <url-pattern>/nerp/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>nerp</servlet-name>
    <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>

nerp-servlet.xml

<beans:bean id="multipartResolver"
    class="com.resources.erp.util.ERPMultiPartResolver">
   <!--  one of the properties available; the maximum file size in bytes  -->
    <beans:property name="maxUploadSize" value="100000"/>
</beans:bean>

ERPMultiPartResolver

public class ERPMultiPartResolver extends CommonsMultipartResolver {
@Override
public boolean isMultipart(final HttpServletRequest request) {
    boolean isMultiPartBoolean = true;
    final String urlFromBrowserWithAppName = String.valueOf(request.getRequestURI());
    String urlFromBrowser = "";

    if(urlFromBrowserWithAppName != null) {
        urlFromBrowser = urlFromBrowserWithAppName.replaceAll(String.valueOf(request.getContextPath()),"");
    }
    if(urlFromBrowser.indexOf("dwr") > 0) {
        isMultiPartBoolean = false;
    }
    else {
        isMultiPartBoolean = super.isMultipart(request);
    }
    return isMultiPartBoolean;
}

}

My MultiPartRequest related upload is getting restricted to the size specified in maxUploadSize property of the ERPMultiPartResolver. But I am not able to restrict the size of the DWR file upload.

I tried using the param-name fileUploadMaxBytes in web.xml but the image size is not getting restricted.

Can someone please help me out on how to restrict the size of the Image through DWR upload when both Spring 3.2.1 and Dwr 3.0 are being used in the project?

I have checked the link

Was it helpful?

Solution

The answer for my above question is that instead of declaring the fileUploadMaxBytes in web.xml in the manner I did above, the declaration should be in the place where you configure your dwrContoller. i.e.

 <dwr:controller id="dwrController" debug="true" >
    <dwr:config-param name="fileUploadMaxBytes" value="1048"/>
 </dwr:controller>

Now with the help of this, I am able to restrict the image size to 1048 bytes.

Earlier my dwrController configuration is as shown below

<dwr:controller id="dwrController" debug="true" />
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top