The default {@link org.apache.commons.fileupload.FileItemFactory}implementation. This implementation creates {@link org.apache.commons.fileupload.FileItem} instances which keep theircontent either in memory, for smaller items, or in a temporary file on disk, for larger items. The size threshold, above which content will be stored on disk, is configurable, as is the directory in which temporary files will be created.
If not otherwise configured, the default configuration values are as follows:
- Size threshold is 10KB.
- Repository is the system default temp directory, as returned by
System.getProperty("java.io.tmpdir")
.
NOTE: Files are created in the system default temp directory with predictable names. This means that a local attacker with write access to that directory can perform a TOUTOC attack to replace any uploaded file with a file of the attackers choice. The implications of this will depend on how the uploaded file is used but could be significant. When using this implementation in an environment with local, untrusted users, {@link #setRepository(File)} MUST be used to configure a repository locationthat is not publicly writable. In a Servlet container the location identified by the ServletContext attribute javax.servlet.context.tempdir
may be used.
Temporary files, which are created for file items, should be deleted later on. The best way to do this is using a {@link FileCleaningTracker}, which you can set on the {@link DiskFileItemFactory}. However, if you do use such a tracker, then you must consider the following: Temporary files are automatically deleted as soon as they are no longer needed. (More precisely, when the corresponding instance of {@link java.io.File} is garbage collected.)This is done by the so-called reaper thread, which is started automatically when the class {@link org.apache.commons.io.FileCleaner}is loaded. It might make sense to terminate that thread, for example, if your web application ends. See the section on "Resource cleanup" in the users guide of commons-fileupload.
@since FileUpload 1.1
@version $Id: DiskFileItemFactory.java 1455094 2013-03-11 11:00:14Z simonetripodi $