2

I am trying to upload very big files greater than 1gb. I am using MultipartConfig and HttpServletRequest.getPart(String) from servlet api. I deployed in my server and tried uploading a file and its working like a charm.

Then I went on reading about MultipartConfig here. I understood that when large files are uploaded it writes parts of the file to a temporary location when the threshold is reached. And later on we have to delete the temporary files using part.delete().

What if I don't want to mention the temporary location? Will something bad happen to my application while uploading big files? I don't want to mention a temporary location becasue we cant gurantee about the production environment.

Krishna Chaitanya
  • 2,533
  • 4
  • 40
  • 74
  • I think this boils down to "what does a `location=""` mean?" The current folder of the server process? The default temporary folder? – Aaron Digulla Sep 10 '14 at 09:50
  • location is used to store files temporarily while the parts are processed or when the size of the file exceeds the specified fileSizeThreshold setting. The api docs also mention that the default temporary location is "". So I think there is no temporary location be default. – Krishna Chaitanya Sep 10 '14 at 09:57
  • Can you try with `location=""` and a small max size to force the server to create temp files, to see what it would do? – Aaron Digulla Sep 10 '14 at 10:06
  • I tried now and its working fine. I think if we dont provide location and try to upload large files, all parts will be in memory only. Am I right? – Krishna Chaitanya Sep 10 '14 at 10:13
  • 1
    I did a search in my server root folder and got this location for the temporary files C:\opt\jboss\jboss-eap-6.1\standalone\tmp\work\jboss.web\default-host\file-upload. I think the the application server knows where to save all the parts by default. – Krishna Chaitanya Sep 10 '14 at 10:28

2 Answers2

2

I don't think there will any problem without specifying any temporary location. Servlet specification 3.0 says every servlet context should have a temporary working directory. So by default all parts are saved to a temporary working directory which is vendor specific.

Krishna Chaitanya
  • 2,533
  • 4
  • 40
  • 74
1

The default location is handled differently by every Application Server.

In Tomcat temporary files exceeding the threshold are saved in a subfolder of the CATALINA_HOME directory (tried with Tomcat 9.0.21).

I found the temporary files to be created here: CATALINA_HOME/work/Tomcat/localhost/MYWEBAPP/upload_3440d3f3_8d15_43ad_bb1d_349599450616_00000005.tmp

hijack
  • 311
  • 2
  • 6