devpia.dextuploadnj.support.common
Class FileUpload
- Minimum version supported
- 1.0.0
- Minimum support environment
- JRE 1.6
- Description
-
The FileUpload class processes multipart data requests.
The FileUpload class is used to handle uploading files in the JSP/Servlet environment.
Environment env = new Environment(); env.setCharEncoding("UTF-8"); env.setTempRepository(System.getProperty("java.io.tmpdir")); env.setDefaultRepository("/file/attach"); env.setAutoMakingDirectory(true); env.setMaxFileSize(1024 * 1024 * 20); env.setMaxTotalSize(1024 * 1024 * 50); env.setWhiteExtensions("jpg,gif,png,doc,xls,ppt,docx,xlsx,pptx,pdf,txt,zip,hwp"); env.setLicenseFilePath("/home/user/license/dextuploadnj.config"); FileUpload dextnj = null; try { dextnj = new FileUpload(request, env); ... dextnj.prepare(); ... } catch (...) { ... } finally { if (dextnj != null) dextnj.close(); }When creating a FileUpload object, you must call the prepare method to handle the upload request. When the calling to the prepare method is completed, the task of creating a temporary file is completed.
- Constructor
-
- Create an object of the FileUpload class.
-
Signatures
public FileUpload(HttpServletRequest request) public FileUpload(HttpServletRequest request, Environment environment)
-
Parameters
Name Type Description request javax.servlet.http.HttpServletRequest the HttpServletRequest object environment devpia.dextuploadnj.Environment the Environment object
- Methods
-
getEnvironment
- Returns an Environment object with upload setting information.
-
Signatures
public Environment getEnvironment()
-
Returns
the Environment object
setEnvironment
- Set an Environmentobject with upload setting information.
-
Signatures
public void setEnvironment(Environment environment)
-
Parameters
Name Type Description environment devpia.dextuploadnj.Environment an Environmentobject -
How to use
Environment env = new Environment(); env.setCharEncoding("UTF-8"); ... env.setLicenseFilePath("Path of the license file"); FileUpload dextnj = new FileUpload(request); dextnj.dkgksetEnvironment(env);
isRemovingWhenClosing
When the close method of the FileUpload object is called, it returns whether or not to delete the temporary file.
-
Signatures
public boolean isRemovingWhenClosing()
-
Returns
true, false
setRemovingWhenClosing
When the close method of the FileUpload object is called, it sets whether to delete temporary file or not.
-
Signatures
public void setRemovingWhenClosing(boolean removingWhenClosing)
-
Parameters
Name Type Description removingWhenClosing boolean the true to delete the temporary file when calling the close method, false otherwise -
How to use
FileUpload dextnj = null; try { dextnj = new FileUpload(request, env); dextnj.setRemovingWhenClosing(false); ... dextnj.prepare(); ... } catch (...) { ... } finally { // Does not delete temporary files. if (dextnj != null) dextnj.close(); }
close
Deletes all resources.
-
Signatures
public void close()
flush
-
Consumes all request data.
After the prepare method has already been called, calling flush method again raises an IllegalStateException.
-
Signatures
public void flush()
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... dextnj.flush();
prepare
-
Separates items from multipart request data and creates uploaded files in the temporary directory. It is a method that must be invoked in order to execute a file upload service.
-
Signatures
public void prepare()
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... dextnj.prepare();
getMultipartCollection
- Returns a MultipartCollection object that has string, file fields.
-
Signatures
public MultipartCollection getMultipartCollection()
-
Returns
a MultipartCollection object
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... MultipartCollection dextMulti = dextnj.getMultipartCollection();
getFormItemCount
- Returns the number of string fields.
-
Signatures
public int getFormItemCount()
-
Returns
The number of string fieldss
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... int formCount = dextnj.getFormItemCount();
getFileItemCount
- Returns the number of file fields.
-
Signatures
public int getFileItemCount()
-
Returns
The number of file fields
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... int fileCount = dextnj.getFileItemCount();
getFormItemNames
- Returns a java.util.Iterator object for all string fields.
-
Signatures
public Iterator<String> getFormItemNames()
-
Returns
a java.util.Iterator object
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... Iterator<String> formNames = dextnj.getFormItemNames();
getFileItemNames
- Returns a java.util.Iterator object for all file fields.
-
Signatures
public Iterator<String> getFileItemNames()
-
Returns
a java.util.Iterator object
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... Iterator<String> formNames = dextnj.getFileItemNames();
getFormItem
-
Returns a FormItem object corresponding to the specified order or name. It returns the first item if there are multiple forms of the same name.
-
Signatures
public FormItem getFormItem(int index) public FormItem getFormItem(String name)
-
Parameters
Name Type Description index int Sequence value name java.lang.String Name -
Returns
A FormItemobject
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... FormItem formitem = dextnj.getFormItem(index);
getFormItemValue
-
Returns the value of the string field corresponding to the specified order or name.
-
Signatures
public String getFormItemValue(int index) public String getFormItemValue(String name)
-
Parameters
Name Type Description index int Sequence value name java.lang.String Name -
Returns
a value of string field
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... String strValue = dextnj.getFormItemValue(index); // or String strValue = dextnj.getFormItemValue(name);
getFormItems
Returns a list(java.util.ArrayList <FormItem>) corresponding to all or the specified name.
-
Signatures
public List<FormItem> getFormItems() public List<FormItem> getFormItems(String name)
-
Parameters
Name Type Description name java.lang.String Name -
Returns
A list(java.util.List<FormItem>)
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... List<FormItem> formitems = dextnj.getFormItems(); // or List<FormItem> formitems = dextnj.getFormItems(name);
getFileItem
-
Returns a FileItem object corresponding to the specified order or name.
-
Signatures
public FileItem getFileItem(int index) public FileItem getFileItem(String name) // Supported since version 2.5.0 public FileItem getFileItem()
-
Parameters
Name Type Description index int Sequence value name java.lang.String Name -
Returns
A FileItem object
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... FileItem fileitem = dextnj.getFileItem(index);
getFileItems
Returns a list(java.util.ArrayList<FileItem>) corresponding to all or the specified name.
-
Signatures
public List<FileItem> getFileItems() public List<FileItem> getFileItems(String name)
-
Parameters
Name Type Description name java.lang.String Name -
Returns
A list(java.util.List<FileItem>)
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... List<FileItem> fileitem = dextnj.getFileItems(); // or List<FileItem> fileitem = dextnj.getFileItem(name);
saveAll
- Saves(move/copy) all temporary files.
-
Signatures
public void saveAll(boolean overwrite) public void saveAll(boolean overwrite, boolean copy) public void saveAll(String targetDirectoryPath) public void saveAll(String targetDirectoryPath, boolean overwrite) public void saveAll(String targetDirectoryPath, boolean overwrite, boolean copy) public void saveAll(BulkSaveOption option)
-
Parameters
Name Type Description targetDirectoryPath java.lang.String the directory path to save files 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 BulkSaveOption (Supported from version 2.7.0) The BulkSaveOption object to set options necessary for saving temporary files
-
How to use
FileUpload dextnj = new FileUpload(request, env); ... // 1 dextnj.saveAll(); // 2 dextnj.saveAll("path to the directory"); // 3 dextnj.saveAll("directory path", true); // 4 dextnj.saveAll("directory path", true, true); // 5 BulkSaveOption option = new BulkSaveOption(); option.setTargetDirectoryPath("/home/user/others/"); option.setOverwrite(true); option.setCopy(true); dextnj.saveAll(option);