1

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.

Roman C
  • 49,761
  • 33
  • 66
  • 176
xrcwrn
  • 5,339
  • 17
  • 68
  • 129

3 Answers3

1

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

<constant name="struts.multipart.maxSize" value="10485760"/>
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • I there! your answer help me a lot. Do you know how to edit the default error message? Adding struts.messages.error.file.too.large to global.properties file isn't working for me.. – tviana Jun 26 '14 at 14:06
  • You may try `struts.messages.error.uploading` but what is the actual message? This setting is for overall multipart request. – Roman C Jun 26 '14 at 14:21
  • nop it doesn't work :( it says "he request was rejected because its size (3172035) exceeds the configured maximum (2097152)". I already search on the entire project and not able to find this message.. – tviana Jun 26 '14 at 14:37
  • This is an exception message thrown by underlying framework which you can handle via global or action based exception mapping. – Roman C Jun 26 '14 at 14:48
  • hmm I see.. but how can I do that? – tviana Jun 26 '14 at 14:55
  • May be you ask it as a question (and someones answer it as well :)? – Roman C Jun 26 '14 at 14:57
  • if you want you can help me here ;) http://stackoverflow.com/questions/24434579/change-default-error-message-for-upload-files-on-struts-2 – tviana Jun 26 '14 at 15:34
0

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.

Amol Patil
  • 238
  • 1
  • 2
  • 7
0

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

Admit
  • 4,897
  • 4
  • 18
  • 26