Pregunta

I'm uploading and downloading .xlsx file on the same page using jsf 1.2 and tomahawk inputFileUpload. Upload works fine, even with max file size limitation. When I download and open some Excel spreadsheet I get error with corrupted file. Excel will fix the file but it's annoying to repair it every time. This error is caused by ExtensionFilter in web.xml. When I remove filter from web.xml all works fine.

Is there any solution how to prevent intercepting ExtensionFilter while downloading? Or is there any other way how to manage max file size before I upload file? Thank you

<h:form id="upload_form" styleClass="form" enctype="multipart/form-data">
    <t:saveState value="#{editedPeriodBean.editedPeriod}" />
        <h:panelGrid columns="1">
             <h:outputLabel for="file" value="#{ms['com.selectFile']}:" styleClass="full" />
             <t:inputFileUpload id="file" value="#{editedPeriodBean.uploadedFile}" required="true" onchange="verifyFile(this);"  />
             <h:commandButton id="submit_btn" value="#{ms['com.import']}" action="#{editedPeriodBean.importPaymentsToEditedPeriod}" disabled="true" styleClass="align_right" />
        </h:panelGrid>
</h:form>

web.xml

<filter>
        <filter-name>Extensions Filter</filter-name>
        <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
            <init-param>
                <description>
                    Set the size limit for uploaded files.
                        Format: 10  - 10 bytes
                                10k - 10 KB
                                10m - 10 MB
                                1g  - 1 GB
                </description>
                <param-name>uploadMaxFileSize</param-name>
                <param-value>20m</param-value>
            </init-param>
    </filter>
    <filter-mapping>
        <filter-name>Extensions Filter</filter-name>
        <servlet-name>Faces Servlet</servlet-name>
    </filter-mapping>
¿Fue útil?

Solución

This param in web.xml solves my problem.

<context-param>
    <param-name>org.apache.myfaces.ADD_RESOURCE_CLASS</param-name>
    <param-value>org.apache.myfaces.component.html.util.StreamingAddResource</param-value>
 </context-param>
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top