dextuploadjk.engine
Interface FileItem
- Minimum version
- 1.0.0
- Minimum environment
- Java 17, Jakarta EE 9+
- Description
-
FileItem is an interface that inherits the FieldItem interface and handles information about file elements in multipart data.
# Servlet/JSP environment // Obtain a FileItem object using the getFileItem method of the FileUpload object. // Returns the first FileItem object FileItem itemFirst = fileUpload.getFileItem(0); // Returns the first FileItem object with the field name "name" FileItem itemName = fileUpload.getFileItem("name"); // Returns all FileItem objects with the name "attachements". List<FileItem> attachements = fileUpload.getFileItems("attachements"); // Returns all FileItem objects. List<FileItem> items = fileUpload.getFileItems();# Spring environment // Obtained by casting the MultipartFile object to FileItem. FileItem item = (FileItem) multipartFile;
- Methods
-
Refer to the getFieldName method of the FieldItem interface.
Refer to the getItemType method of the FieldItem interface.
isEmpty
-
Returns whether it is an empty file.
An empty file is a case where fields exist but no actual file information. For files with a length of 0, false is returned.
-
Signatures
boolean isEmpty()
-
Return
true if it is an empty file, false otherwise.
getFilename
-
Returns the file name.
-
Signatures
String getFilename()
-
Return
File name (do not include parent path)
getFilenameWithoutExtension
-
Returns the file name with the extension removed.
-
Signatures
String getFilenameWithoutExtension()
-
Return
File name with extension removed (does not include parent path)
getContentType
-
Returns the file type (MIME-TYPE).
Since the file format is determined by the client at the time of data transmission, it is difficult to use it as an indicator to distinguish the type of file.
-
Signatures
String getContentType()
-
Return
File type (MIME-TYPE), ex) image/png
getTempFilePath
-
Returns the temporary file path.
-
Signatures
String getTempFilePath()
-
Return
temporary file path
getTempFile
-
Returns a temporary file object.
-
Signatures
File getTempFile()
-
Return
A java.io.File object representing a temporary file.
getFileSize
-
Returns the size of the file.
-
Signatures
long getFileSize()
-
Return
File size, default is -1.
getOriginalFileSize
-
Returns the original size of the file.
If the FilterAction setting is set to Flushing, the size of the filtered file becomes 0 bytes. When you want to know the size of the filtered file, you can use the getOriginalFileSize method to find out the original size.
-
Signatures
long getOriginalFileSize()
-
Return
File size, default is -1.
isEligibleFile
-
True is returned only if the isEmpty return value is false and the getFileSize value is greater than 0.
-
Signatures
boolean isEligibleFile()
-
Return
true, false
getExtension
-
Returns the file extension name.
-
Signatures
String getExtension()
-
Return
The extension name of the file includes '.', and if there is no extension name, an empty string is returned.
getLastSavedFilePath
-
When a file is saved using methods such as save or saveAs, the full path of the saved file is returned.
-
Signatures
String getLastSavedFilePath()
-
Return
Full path to saved file
getLastRelativeSavedFilePath (support from version 2.13.0)
-
Returns the relative path to the saved file after calling methods such as save and saveAs.
-
Signatures
String getLastRelativeSavedFilePath()
-
Returns
Returns a subpath of the default save path, where the beginning of the returned path does not contain a path separator. If not a subpath of the default save path, returns the full path to the file.
getLastSavedFilename
-
When a file is saved using methods such as save or saveAs, the name of the saved file is returned.
-
Signatures
String getLastSavedFilename()
-
Return
Name of saved file
deleteTempFile
-
Remove temporary files.
When this method is called, the temporary file is removed and the temporary file information is also deleted. No error occurs even if there are no temporary files.
-
Signatures
void deleteTempFile()
saveAs
-
Save (move, copy) the temporary file to the destination.
Used when changing and saving a file name that is different from the original file name.
It is recommended to use the save method with the FileSaveOption parameter instead of saveAs.
-
Signatures
String saveAs(String targetFilename) String saveAs(String targetFilename, boolean overwrite) String saveAs(String targetFilename, boolean overwrite, boolean copy) String saveAs(String targetDirectoryPath, String targetFilename) String saveAs(String targetDirectoryPath, String targetFilename, boolean overwrite) String saveAs(String targetDirectoryPath, String targetFilename, boolean overwrite, boolean copy)
-
Parameters
Name Type Description targetDirectoryPath java.lang.String Directory path to save the file targetFilename java.lang.String File name to save overwrite boolean When there is a file with the same name in the destination, if the parameter value is true, it is overwritten, and if it is false, it is saved with a non-duplicate file name.
When DEXTUploadJK saves a file, if there is a file with the same file name, a suffix value is automatically added. However, in systems that process many requests simultaneously, such as on the web, there is a high possibility that the same file name will be created despite suffix processing. Therefore, even if the overwrite argument value is the default or false, an error in which file writing fails often occurs. To avoid this situation as much as possible, do not save the original file name as is, but specify a name that will avoid duplication as much as possible.
copy boolean If the parameter value is true, temporary files are not removed even after saving the file. If false, temporary files are removed immediately after saving is completed.
-
Return
Full path to saved file
-
Uses
// If the temporary file path is '/home/user/temp/temp_name.txt' and the default storage directory is '/home/user/files', save the temporary file to the '/home/user/files/uploaded_file.txt' path. do. item.saveAs("uploaded_file.txt"); // When the temporary file path is '/home/user/temp/temp_name.txt' and the default storage directory is '/home/user/files', change the directory path to save temporary files to '/home/user/others/ Save it to the path ‘uploaded_file.txt’. item.saveAs("/home/user/others/", "uploaded_file.txt");
save
-
Save (move, copy) the temporary file to the destination.
Used when saving with the same file name as the original file name.
It is recommended to use a method with the FileSaveOption parameter instead of multiple overloading methods.
-
Signatures
String save() String save(boolean overwrite) String save(boolean overwrite, boolean copy) String save(String targetDirectoryPath) String save(String targetDirectoryPath, boolean overwrite) String save(String targetDirectoryPath, boolean overwrite, boolean copy) String save(FileSaveOption option)
-
Parameters
Name Type Description targetDirectoryPath java.lang.String Directory path to save the file overwrite boolean When there is a file with the same name in the destination, if the parameter value is true, it is overwritten, and if it is false, it is saved with a non-duplicate file name.
When DEXTUploadJK saves a file, if there is a file with the same file name, a suffix value is automatically added. However, in systems that process many requests simultaneously, such as on the web, there is a high possibility that the same file name will be created despite suffix processing. Therefore, even if the overwrite argument value is the default or false, an error in which file writing fails often occurs. To avoid this situation as much as possible, do not save the original file name as is, but specify a name that will avoid duplication as much as possible.
copy boolean If the parameter value is true, temporary files are not removed even after saving the file. If false, temporary files are removed immediately after saving is completed.
option FileSaveOption An object that sets options required when saving temporary files.
-
Return
Full path to saved file
-
Uses
// If the temporary file path is '/home/user/temp/temp_name.txt' and the default storage directory is '/home/user/files', save the temporary file to the '/home/user/files/temp_name.txt' path. do. item.save(); // When the temporary file path is '/home/user/temp/temp_name.txt' and the default storage directory is '/home/user/files', change the directory path to save temporary files to '/home/user/others/ Save it to the path ‘temp_name.txt’. item.save("/home/user/others/"); // Same as item.save("/home/user/others/") FileSaveOption option = new FileSaveOption(); option.setTargetDirectoryPath("/home/user/others/"); item.save(option);
getFileCopyOption
-
Returns the method for copying a file.
-
Signatures
FileCopyOption getFileCopyOption()
-
Return
Default FileCopyOption.Channel
setFileCopyOption
-
Set the method for copying files.
For copy methods, refer to the FileCopyOption enumeration.
The setFileCopyOption method on the Environment class affects all operations that copy files, while the setFileCopyOption method on the FileItem interface only affects the current file operation.
-
Signatures
void setFileCopyOption(FileCopyOption fileCopyOption)
-
Parameters
Name Type Description fileCopyOption dextuplodjk.engine.FileCopyOption This is an enumeration value indicating the file copy method. -
Uses
// Set as stream copy method. item.setFileCopyOption(FileCopyOption.Stream);
get
-
Returns file data.
An exception may occur if memory is insufficient, and only up to 2GB is supported.
-
Signatures
byte[] get(boolean caching)
-
Parameters
Name Type Description caching boolean If the parameter value is true, data is read from the file and the file data is cached inside the item object.
If there is cached data, the cached data is copied to memory and returned without reading the file.
-
Return
A byte array object representing file data.
-
Uses
// Returns file data as a byte array and allows the data to be cached internally. byte[] data = item.get(true);
isCached
-
Returns whether there is cached file data.
-
Signatures
boolean isCached()
-
Return
True if there is cached data, false otherwise.
removeCache
-
Delete cached file data.
-
Signatures
void removeCache()
getEnvironment
-
Returns an Environment object containing file upload setting values.
-
Signatures
Environment getEnvironment()
-
Return
Environment object
isFiltered
-
Returns whether the file is the target of filtering.
This can only be used when the FilterAction setting is Flushing.
-
Signatures
boolean isFiltered()
-
Return
true if filtered, false otherwise
-