I am trying to implement a file upload in JSP/Struts2, and I noted a strange behaviour. I declared my action that way in struts.xml to limit file size to 1MB
<action name="massInsert" class="massInsertAction">
<interceptor-ref name="fileUpload">
<param name="allowedTypes">
image/png,image/gif,image/jpeg
</param>
<param name="maximumSize">1000000</param>
</interceptor-ref>
<interceptor-ref name="defaultStack"/>
<result name="success">/WEB-INF/jsp/massInsert/massInsert.jsp</result>
<result name="validationError">/WEB-INF/jsp/massInsert/massInsert.jsp</result>
</action>
it works pretty well, non image files and images over 1MB throw an error. The only issue is that the file that was too big got fully uploaded on the server temp folder anyway before being deleted.
Is there a way to stop the uploading as soon as the limit is hit ?
Edit: Quaternion's solution works, when the request goes over the maximum set with the following line an error is thrown and everything stops. No file is written to disk
<constant name="struts.multipart.maxSize" value="1000000" />