www.dextsolution.com
DEXTUPLOAD
NJ
menu toggleReference > devpia > dextuploadnj > FileItem

devpia.dextuploadnj
Interface FileItem

Minimum version supported
1.0.0
Minimum support environment
JRE 1.6
Description

FileItem handles information about the elements of a file from multipart data as an interface inheriting the FieldItem interface.

FileUpload dextnj = new FileUpload(request, env);
dextnj.prepare();
...
// Returns the number of the MultipartFileItem objects.
int formCount = dextnj.getFileItemCount();

// Returns the iterator of the field name pointing to the MultipartFileItem object.
Iterator<String> iterator = dextnj.getFileItemNames();

// Returns the 0th MultipartFileItem object.
FileItem item = dextnj.getFileItem(0);

// Returns the first MultipartFileItem object with field name is "name".
FileItem item = dextnj.getFileItem("name");

// Returns all FilMultipartFileItem objects with the name is "attachements".
List<FileItem> orders = dextnj.getFileItems("attachements");

// Returns all MultipartFileItem objects.
List<FileItem> orders = dextnj.getFileItems();
Methods

getFieldName

See the getFieldName method of the FieldItem interface.

getItemType

See the getItemType method of the FieldItem interface.

isEmpty

  • Returns whether or not it is an empty file. An empty file is a case where a field exists, but there is no actual file information. In case of a file of length 0, returns false.

  • Signatures

    boolean isEmpty()
  • Returns

    true, false

getFilename

  • Returns the file name.

  • Signatures

    String getFilename()
  • Returns

    The file name(It does not include parent path.)

getFilenameWithoutExtension

  • Returns the file name with the extension removed.

  • Signatures

    String getFilenameWithoutExtension()
  • Returns

    The file name with extension removed(It does not include parent path.)

getContentType

  • Returns the mime type of the file.

    Since the mime type is a matter decided by the client at the time of data transfer, it is difficult to use it as a solution for distinguishing the file type.

  • Signatures

    String getContentType()
  • Returns

    The mime-type of the file, ex) image/png

getTempFilePath

  • Returns the path of the temporary file.

  • Signatures

    String getTempFilePath()
  • Returns

    The path of the temporary file

getTempFile

  • Returns a temporary file object.

  • Signatures

    File getTempFile()
  • Returns

    A java.io.File object representing a temporary file

getFileSize

  • Returns the size of the file.

  • Signatures

    long getFileSize()
  • Returns

    The file size(default is -1.)

getOriginalFileSize

  • Returns the original size of the file.

    When the FilterAction setting is set to Flushing, the size of the filtered file is 0 byte. If you want to know the size of the filtered file use the getOriginalFileSize method to know the original size.

  • Signatures

    long getOriginalFileSize()
  • Returns

    The file size(default is -1.)

isEligibleFile

  • Return true if the return value of the isEmpty method is false and the return value of the getFileSize method is greater than 0.

  • Signatures

    boolean isEligibleFile()
  • Returns

    true, false

getExtension

  • Returns the extension name of the file.

  • Signatures

    String getExtension()
  • Returns

    The extension name(If there is no extension name or extension name of the file containing '.', returns empty string.)

getLastSavedFilePath

  • When saving a file using a method such as save or saveAs, it returns the full path of the saved file.

  • Signatures

    String getLastSavedFilePath()
  • Returns

    The full path of 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 saving a file using a method such as save or saveAs, it returns the name of the saved file.

  • Signatures

    String getLastSavedFilename()
  • Returns

    The name of the saved file

deleteTempFile

  • Delete the temporary file.

    Calling this method deletes the temporary file and also deletes the information of the temporary file. Even if there is no temporary file, no error occurs.

  • Signatures

    void deleteTempFile()

saveAs

  • Saves(move or copy) the temporary file. If you want to change to a file name different from the original file name, uses this method.

  • 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 The directory path where the file is stored
    targetFilename java.lang.String The file name to save
    overwrite boolean

    When the destination has a file with the same name, if the value of parameters is true, the file will be overwrited, if false, the file will be saved with a non-overlapping file name.

    When saving a file, DEXTUploadNJ automatically takes a value of suffix if there is a file with the same file name. However, in the case of a system that processes many requests at the same time like the Web, there is a high possibility that the same file name is generated despite suffix processing. Therefore, even when the value of the overwrite argument is false, in many cases, an error occurs to write the file. In order to avoid this situation to the utmost, do not save the original file name as it is, and specify it as name where duplication has not occurred as much as possible.

    copy boolean

    If the value of Parameters is true, it does not delete the temporary file after saving the file. If false, deleting the temporary file after saving is immediately completed.

  • Returns

    The full path of saved file

  • How to use

    // If the path of the temporary file is "/home/user/temp/temp_name.txt" and the default save directory is "/home/user/files", temporary file is saved to "/home/user/files/uploaded_file.txt".
    item.saveAs("uploaded_file.txt");
    
    // If the path of the temporary file is "/home/user/temp/temp_name.txt", the temporary file path is saved to "home/user/others/uploaded_file.txt". 
    item.saveAs("/home/user/others/", "uploaded_file.txt");

save

  • Saves(move or copy) the temporary file. It is used to save with the same file name as the original file name.

  • 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 The directory path where the file is stored
    overwrite boolean

    When the destination has a file with the same name, if the value of parameters is true, the file will be overwrited, if false, the file will be saved with a non-overlapping file name.

    When saving a file, DEXTUploadNJ automatically takes a value of suffix if there is a file with the same file name. However, in the case of a system that processes many requests at the same time like the Web, there is a high possibility that the same file name is generated despite suffix processing. Therefore, even when the value of the overwrite argument is false, in many cases, an error occurs to write the file. In order to avoid this situation to the utmost, do not save the original file name as it is, and specify it as name where duplication has not occurred as much as possible.

    copy boolean

    If the value of Parameters is true, it does not delete the temporary file after saving the file. If false, deleting the temporary file after saving is immediately completed.

    option FileSaveOption

    (Supported from version 2.7.0) The FileSaveOption object to set options necessary for saving temporary files

  • Returns

    The full path of saved file

  • How to use

    // If the temporary file path is "/home/user/temp/temp_name.txt" and the default save directory is "/home/user/files", the temporary file will be "/home/user/files/temp_name.txt".
    item.save();
    
    // If the temporary file path is "/home/user/temp/temp_name.txt", the temporary file will be "/home/user/others/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 (Supported since version 1.1.0)

  • Returns the method of copying the file.

  • Signatures

    FileCopyOption getFileCopyOption()
  • Returns

    The FileCopyOption value

setFileCopyOption (Supported since version 1.1.0)

  • Sets the method of copying files. For the method of copying, see the FileCopyOption enumeration type.

    The setFileCopyOption method of the Environment class affects all operations copying files, but the setFileCopyOption method of the FileItem interface affects only the operation of the current file.

  • Signatures

    void setFileCopyOption(FileCopyOption fileCopyOption)
  • Parameters

    Name Type Description
    fileCopyOption devpia.dextuplodnj.FileCopyOption The FileCopyOption value
  • How to use

    item.setFileCopyOption(FileCopyOption.Stream);

get (support from version 2.1.1)

  • Returns file data. If memory is insufficient, an exception can occur, and it supports up to 2 GB only.

  • Signatures

    byte[] get(boolean caching)
  • Parameters

    Name Type Description
    caching boolean

    When the value of the parameter is true, after reading the data from the file, the file data is cached inside this object. If there is cached data, next time, it copies and returns the cached data in memory without reading the file.

  • Returns

    The byte array object of file data

  • How to use

    // Make the data of the file and return to the byte array and cache the data internally.
    byte[] data = item.get(true);

isCached (Supported since version 2.1.1)

  • Returns whether or not there is cached data of the file.

  • Signatures

    boolean isCached()
  • Returns

    true, false

removeCache (Supported since version 2.1.1)

  • Deletes the cached data of the file.

  • Signatures

    void removeCache()

getEnvironment (Supported since version 2.5.0)

  • Returns an Environment object containing configuration values.

  • Signatures

    Environment getEnvironment()
  • Returns

    Environment object

isFiltered (Supported since version 2.5.0)

  • Returns whether the file is a filtered.

    It can be used only when the FilterAction is Flushing.

  • Signatures

    boolean isFiltered()
  • Returns

    true, false