I'm facing trouble while uploading large files to the server for my project. I have modified maxPostSize and maxHttpHeaderSize in server.xml as suggested in this article but it's showing java.lang.OutOfMemoryError. What to do?
Asked
Active
Viewed 5,621 times
0
-
Have you consider using [Apache Commons FileUpload](https://commons.apache.org/proper/commons-fileupload/streaming.html) ? A good API, easy to use. Don't think 100MB file will be a problem. – ikos23 Apr 21 '18 at 19:00
-
@john It's much easier to use the servlet-provided API to accept uploads (because the API is simpler AND the container provides the mechanism to do it so the application does not need to package that dependency). Oddly enough, Tomcat uses commons-fileupload behind the scenes. – Christopher Schultz Apr 23 '18 at 13:16
1 Answers
1
Have a look at the documentation. In particular, you're interested in the maxFileSize
parameter, which you can set either with annotations or xml.
Directly from the link above,
@MultipartConfig(location="/tmp", fileSizeThreshold=1024*1024,
maxFileSize=1024*1024*5, maxRequestSize=1024*1024*5*5)
or
<multipart-config>
<location>/tmp</location>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
So for example, you can annotate your servlet like so:
@MultipartFileConfig( options )
public class YourServlet extends HttpServlet {
...
or add the equivalent xml in the config if using xml.

geco17
- 5,152
- 3
- 21
- 38