I am trying to implement file upload in JSP / Struts2 and I have noticed strange behavior. I declared my action this way in struts.xml to limit the file size to 1 MB
<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 very well, but not image files and images larger than 1 MB give an error. The only problem is that the file, which was too large, was completely uploaded to the serverโs temporary folder before it was deleted.
Is there a way to stop the download as soon as the limit is removed?
Edit: The Quaternion solution works when the query moves to the maximum set with the next line, an error is thrown, and everything stops. File cannot be written to disk
<constant name="struts.multipart.maxSize" value="1000000" />
source share