Limit Struts2 maximum upload file size without downloading the entire file

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" /> 
+4
source share
1 answer

There are two file size options that you have to do with individual file sizes, others with a maximum multi-part file size. This is because you can get an array of files if you want (just change the type of setters from file to file [], so simple), say struts.multipart.maxSize is set to 10 MB and the file size ( maximumSize ) is set to 1 MB You should be able to receive 10 1 MB files. Therefore, the buffer should be increased to 10 MB.

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.multipart.maxSize" value="1000000" /> <action name="doUpload" class="com.example.UploadAction"> <interceptor-ref name="basicStack"/> <interceptor-ref name="fileUpload"> <param name="maximumSize">500000</param> </interceptor-ref> <interceptor-ref name="validation"/> <interceptor-ref name="workflow"/> <result name="success">good_result.jsp</result> </action> </struts> 

Source: https://cwiki.apache.org/confluence/display/WW/File+Upload#FileUpload-FileSizeLimits

+4
source

Source: https://habr.com/ru/post/1337378/


All Articles