Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts 2 File Upload Interceptor configuration problems

I'm having two problems when trying to configure the Struts 2 File Upload Interceptor in my application. I want to change the parameter maximumSize (the default value is 2 MB, I need it to be 5 MB) and the message resource struts.messages.error.file.too.large (the app locale is pt_BR, so the message is in portuguese, not english).

The app current configuration follows:

struts.properties

struts.locale=pt_BR 
struts.custom.i18n.resources=MessageResources

struts.xml

<package name="default" namespace="/" extends="struts-default">
    <interceptors>
        <interceptor name="login" class="br.com.probank.interceptor.LoginInterceptor"/>
        <interceptor-stack name="defaultLoginStack">
            <interceptor-ref name="login" />
            <interceptor-ref name="defaultStack"/>
        </interceptor-stack>
    </interceptors>

    <default-interceptor-ref name="defaultLoginStack" />
    ...
</package>

...
<package name="proposta" namespace="/proposta" extends="default">
    <action name="salvarAnexoProposta" method="salvarAnexoProposta" class="br.com.probank.action.AnexoPropostaAction">
        <interceptor-ref name="defaultLoginStack">
            <param name="fileUpload.maximumSize">5242880</param>
        </interceptor-ref>
        <result name="success">/jsp/listagemAnexosPropostaForm.jsp</result>
        <result name="input">/jsp/crudAnexoPropostaForm.jsp</result>
        <result name="error">/jsp/error.jsp</result>
        <result name="redirect" type="redirect">${redirectLink}</result>
    </action>
</package>

MessageResources.properties

...
struts.messages.error.file.too.large=O tamanho do arquivo...

There is nothing special about my Action implementation and my JSP code. They follow the example found http://struts.apache.org/2.1.6/docs/file-upload-interceptor.html. When I try to upload a file with more than 5 MB the app shows the message "the request was rejected because its size (6229458) exceeds the configured maximum (2097152)" - the default File Upload message with the default maximumSize value.

I try to put the message resource struts.messages.error.file.too.large in a struts-messages.properties but the message didn't change after that. What is the proper way to configure the File Upload Interceptor? I'm using Struts 2 2.1.7. Thanks in advance.

like image 852
Matheus Moreira Avatar asked Sep 18 '09 17:09

Matheus Moreira


1 Answers

Finally solved the entire puzzle! struts.xml and MessageResource.properties were correctly configured. The problem was struts.multipart.maxSize value. This value have to be bigger than the desired upload limit (5242880 in my app), so I set it as 10000000. If struts.multipart.maxSize value is equal or less then fileUpload.maximumSize the library used by Struts 2 to do the upload stops the upload process (and writes the error message) before the file upload interceptor has a chance to do its job.

like image 51
Matheus Moreira Avatar answered Sep 22 '22 14:09

Matheus Moreira