Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Struts2 Upload File, validating size and content type file before send file

I have a problem with Struts 2 and its file upload interceptor. It is have validated my content type and my file size, but the upload process dont stop. Example my upload limit is 2Mb and user send a file with 500MB, the interceptor struts 2 log that file is too larger, but continue upload file

I'd like to stop the upload process, in error case, beacuse the struts2 have returned to my page only when the sending file is finished.

Thanks

like image 494
William Miranda Avatar asked Nov 04 '22 14:11

William Miranda


1 Answers

You can't in Struts - since Struts doesn't get hold of the response object until your servlet container has finished processing it.

However - most containers have a means of controlling upload file sizes and, for tomcat, this is the maxPostSize parameter (default is 2GB) - as far as I can tell tomcat will count the number of incoming bytes and then exit if this value is exceeded. i.e Tomcat will not continue reading past maxPostSize. Other containers will have similair configuration parameters. I've never used it so I can't be of any further help here.

If you have nested containers/serves (for example, tomcat sitting behind Apache Web Server) make sure you configure the right one

like image 156
user497087 Avatar answered Nov 09 '22 18:11

user497087