Upload video in struts 2

2020-04-17 08:24发布

问题:

I want to upload video in my struts 2 web application. For this I am using File upload interceptor . My problem is that, I am able to upload image and text file successfully, but not able to video and flash files, file parameters are not get initialize in my action. I am doing in the following way:

entry in struts.xml :

<action name="uploadFile"
        class="com.infoshore.noticeboard.actions.DssUploadFileAction" method="addUploadContent">
        <interceptor-ref name="fileUpload">
            <param name="allowedTypes">
                image/png,image/gif,image/jpeg,image/pjpeg,image/jpg,video/x-ms-rmvb,video/x-ms-wmv,video/x-ms-avi,
                video/fli,video/x-fli,video/x-atomic3d-feature,video/gl,video/x-gl,video/x-isvideo,video/mpeg,video/x-motion-jpeg,video/quicktime,video/x-sgi-movie,
                video/x-mpeg,video/vnd.rn-realvideo,video/x-scm
            </param>
            <!-- <param name="allowedTypes">text/plain</param>  -->
            <param name="maximumSize">10485760</param>
        </interceptor-ref>
        <interceptor-ref name="logininterceptor" />
        <interceptor-ref name="params" />
        <interceptor-ref name="basicStack" />
        <result name="success" type="chain">dssUploadContent</result>
        <result name="input" type="chain">dssUploadContent</result>
        <result name="login">login.jsp</result>
    </action>

What wrong I am doing here, please tell me. Thanks.

回答1:

The maximumSize is per-file, configured globally OR per-Action

<interceptor-ref name="fileUpload">
    <param name="maximumSize">10485760</param>
</interceptor-ref>

The default is 2097152 bytes (2 MB)

The multipart.maxSize

<constant name="struts.multipart.maxSize" value="100485760" />

is per-request, configured only globally;

The default is 2097152 bytes (2 MB) (source on File Upload Advanced Configuration)


Mixing this two parameters allows you to upload N files of maximumSize MB each one in a single request, if they do not break the struts.multipart.maxSize MB defined limit.

More info here