Top Description Fields Constructors Methods
org.apache.tomcat.util.http.fileupload.disk

public Class DiskFileItemFactory

extends Object
implements FileItemFactory
Class Inheritance
All Implemented Interfaces
org.apache.tomcat.util.http.fileupload.FileItemFactory
Imports
java.io.File, org.apache.tomcat.util.http.fileupload.FileItem, .FileItemFactory

The default org.apache.tomcat.util.http.fileupload.FileItemFactory implementation. This implementation creates org.apache.tomcat.util.http.fileupload.FileItem instances which keep their content 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:

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, setRepository(File) MUST be used to configure a repository location that is not publicly writable. In a Servlet container the location identified by the ServletContext attribute jakarta.servlet.context.tempdir may be used.

Temporary files, which are created for file items, will be deleted when the associated request is recycled.

Since
1.1

Field Summary

Modifier and TypeField and Description
public static final int
DEFAULT_SIZE_THRESHOLD

The default threshold above which uploads will be stored on disk.

private String
defaultCharset

Default content charset to be used when no explicit charset parameter is provided by the sender.

private File
repository

The directory in which uploaded files will be stored, if stored on disk.

private int
sizeThreshold

The threshold above which uploads will be stored on disk.

Constructor Summary

AccessConstructor and Description
public
DiskFileItemFactory()

Constructs an unconfigured instance of this class.

public
DiskFileItemFactory(final int
The threshold, in bytes, below which items will be retained in memory and above which they will be stored as a file.
sizeThreshold
,
final File
The data repository, which is the directory in which files will be created, should the item size exceed the threshold.
repository
)

Constructs a preconfigured instance of this class.

Method Summary

Modifier and TypeMethod and Description
public FileItem

Returns:

The newly created file item.
createItem
(final String
The name of the form field.
fieldName
,
final String
The content type of the form field.
contentType
,
final boolean
true if this is a plain form field; false otherwise.
isFormField
,
final String
The name of the uploaded file, if any, as supplied by the browser or other client.
fileName
)

Implements org.apache.tomcat.util.http.fileupload.FileItemFactory.createItem.

Create a new DiskFileItem instance from the supplied parameters and the local factory configuration.

public String

Returns:

the default charset
getDefaultCharset
()

Returns the default charset for use when no explicit charset parameter is provided by the sender.

public File

Returns:

The directory in which temporary files will be located.
getRepository
()

Returns the directory used to temporarily store files that are larger than the configured size threshold.

public int

Returns:

The size threshold, in bytes.
getSizeThreshold
()

Returns the size threshold beyond which files are written directly to disk.

public void
setDefaultCharset(final String
the default charset
pCharset
)

Sets the default charset for use when no explicit charset parameter is provided by the sender.

public void
setRepository(final File
The directory in which temporary files will be located.
repository
)

Sets the directory used to temporarily store files that are larger than the configured size threshold.

public void
setSizeThreshold(final int
The size threshold, in bytes.
sizeThreshold
)

Sets the size threshold beyond which files are written directly to disk.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DEFAULT_SIZE_THRESHOLDback to summary
public static final int DEFAULT_SIZE_THRESHOLD

The default threshold above which uploads will be stored on disk.

defaultCharsetback to summary
private String defaultCharset

Default content charset to be used when no explicit charset parameter is provided by the sender.

repositoryback to summary
private File repository

The directory in which uploaded files will be stored, if stored on disk.

sizeThresholdback to summary
private int sizeThreshold

The threshold above which uploads will be stored on disk.

Constructor Detail

DiskFileItemFactoryback to summary
public DiskFileItemFactory()

Constructs an unconfigured instance of this class. The resulting factory may be configured by calling the appropriate setter methods.

DiskFileItemFactoryback to summary
public DiskFileItemFactory(final int sizeThreshold, final File repository)

Constructs a preconfigured instance of this class.

Parameters
sizeThreshold:int

The threshold, in bytes, below which items will be retained in memory and above which they will be stored as a file.

repository:File

The data repository, which is the directory in which files will be created, should the item size exceed the threshold.

Method Detail

createItemback to summary
public FileItem createItem(final String fieldName, final String contentType, final boolean isFormField, final String fileName)

Implements org.apache.tomcat.util.http.fileupload.FileItemFactory.createItem.

Create a new DiskFileItem instance from the supplied parameters and the local factory configuration.

Parameters
fieldName:String

The name of the form field.

contentType:String

The content type of the form field.

isFormField:boolean

true if this is a plain form field; false otherwise.

fileName:String

The name of the uploaded file, if any, as supplied by the browser or other client.

Returns:FileItem

The newly created file item.

Annotations
@Override
getDefaultCharsetback to summary
public String getDefaultCharset()

Returns the default charset for use when no explicit charset parameter is provided by the sender.

Returns:String

the default charset

getRepositoryback to summary
public File getRepository()

Returns the directory used to temporarily store files that are larger than the configured size threshold.

Returns:File

The directory in which temporary files will be located.

See Also
setRepository(java.io.File)
getSizeThresholdback to summary
public int getSizeThreshold()

Returns the size threshold beyond which files are written directly to disk. The default value is 10240 bytes.

Returns:int

The size threshold, in bytes.

See Also
setSizeThreshold(int)
setDefaultCharsetback to summary
public void setDefaultCharset(final String pCharset)

Sets the default charset for use when no explicit charset parameter is provided by the sender.

Parameters
pCharset:String

the default charset

setRepositoryback to summary
public void setRepository(final File repository)

Sets the directory used to temporarily store files that are larger than the configured size threshold.

Parameters
repository:File

The directory in which temporary files will be located.

See Also
getRepository()
setSizeThresholdback to summary
public void setSizeThreshold(final int sizeThreshold)

Sets the size threshold beyond which files are written directly to disk.

Parameters
sizeThreshold:int

The size threshold, in bytes.

See Also
getSizeThreshold()