Not able to upload large files

流过昼夜 提交于 2021-02-19 08:35:07

问题


I would like to upload large amount of image file (max size 10mb) for that I am using following configuration is struts.xml

<interceptors>
    <interceptor-stack name="fileUploadStack">
        <interceptor-ref name="exception" />
        <interceptor-ref name="alias" />
        <interceptor-ref name="servletConfig" />
        <interceptor-ref name="prepare" />
        <interceptor-ref name="i18n" />
        <interceptor-ref name="chain" />
        <interceptor-ref name="debugging" />
        <interceptor-ref name="profiling" />
        <interceptor-ref name="scopedModelDriven" />
        <interceptor-ref name="modelDriven" />
        <interceptor-ref name="fileUpload">
            <param name="maximumSize">10485760</param>
            <param name="allowedTypes">image/jpg,image/jpeg,image/gif,image/png,image/pjpeg</param>
        </interceptor-ref>
        <interceptor-ref name="checkbox" />
        <interceptor-ref name="staticParams" />
        <interceptor-ref name="actionMappingParams" />
        <interceptor-ref name="params">
            <param name="excludeParams"> dojo\..*,^struts\..*</param>
        </interceptor-ref>
        <interceptor-ref name="conversionError" />
        <interceptor-ref name="validation">
            <param name="excludeMethods"> input,back,cancel,browse</param>
        </interceptor-ref>
        <interceptor-ref name="workflow">
            <param name="excludeMethods"> input,back,cancel,browse</param>
        </interceptor-ref>
    </interceptor-stack>
</interceptors>
   <action name="ownmessageswithimage" class="social.action.UserMessages" method="insertImage">
    <result name="success">/pages/profile/userSingleMessage.jsp</result>
    <result name="input">/pages/errorpages/ajaxError.jsp</result>
    <result name="login">/pages/pleaselogin.jsp</result>
</action>

Edit: This is my jsp file code

     <script  type="text/javascript" src="js/jquery.form.js"></script>
        <form id="own_message_post" action="ownmessageswithimage" method="post"> 
            <input id="fileupload" type="file" name="user_post_image"  data-url="ownmessages" />
<textarea name="message"  rows="4" cols="45" id="text_message_status" 
                  ></textarea><br>
                    <input type="submit" value="Post" id="submit_form_button" 
                   style="background:#004091;padding: 2px 20px 2px 20px;color: whitesmoke;font-weight: bold" />
        </form>
        <script type="text/javascript">
            $('#own_message_post').ajaxForm(function(data) {

                $('#fileupload').val("");

            }); 
        </script>

I am using malsup asynchronous file upload script But problem is that it is not uploading large file up to 10 mb. How to make it possible.


回答1:


You should add the constant to configuration file to allow multipart content size up to 10M

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



回答2:


I am not sure if it helps but I have used multipart encryption to upload large files when using a form at client side.

this is to send a file from file input box in form. I am not sure about struts though.




回答3:


It seems <param name="allowedTypes">image/jpg,image/jpeg,image/gif,image/png,image/pjpeg</param> allows you upload only images of such types. Add another MIME types there, e.g. text/xml or any other types



来源:https://stackoverflow.com/questions/19225881/not-able-to-upload-large-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!