www.dextsolution.com
DEXTUPLOAD
JK
menu toggleProduct information > Extension file-upload

Extension file-upload

In DEXTUploadJK, uploading a file larger than 2GB is called 'Extension file-upload'. DEXTUploadJK provides the ability to process Extension file-upload when used with its component products such as DEXTUploadX5 (HTML5-based). (Extension file-upload is only possible when linked with our own components and is not supported by DEXTUploadJK alone.)

Extension file-upload is handled differently from regular file uploads. In a typical file upload, to send 10 files, all 10 can be sent in one request, but in Extension file-upload, at least 20 to thousands of requests may be sent to the server depending on the situation. DEXTUploadJK's Extension file-upload function basically supports continuous upload, so the product communicates with the server in advance, and since the file is split and transmitted, the number of requests increases depending on the divided size (chunk). . For example, assuming that you upload 10 files of 2.5GB in size, and transmitting them in chunks of about 10MB in size, about 2,500 requests may occur. However, since DEXTUploadJK completely handles the task of merging split files into one, developers only need to process the task of saving (transferring) files to the destination a total of 10 times.

Extension file-upload function is entirely handled by the JKExtensionUploadFilter class. Since this class is a filter class, it is automatically loaded by a Java servlet container (such as Tomcat) and handles Extension file-upload without any code-level creation or invocation.

The following is how to set JKExtensionUploadFilter in DD (web.xml).

# web.xml
<filter>
    <filter-name>extensionUploadFilter</filter-name>
    <filter-class>dextuploadjk.support.common.JKExtensionUploadFilter</filter-class>
    <!-- Setting parameters omitted -->
</filter>
<filter-mapping>
    <filter-name>extensionUploadFilter</filter-name>
    <!-- 
    Map the servlet or URL where you want Extension file-upload to be processed.
    <servlet-name>Serlvet name</servlet-name>
    <url-pattern>URL mapping</url-pattern>
    -->
</filter-mapping>
In case of Servlet or JSP environment

Temporary files processed through the JKExtensionUploadFilter filter can be processed using the FileUpload class in servlet or JSP.

FileUpload fileUpload = null;
try {
    fileUpload = new FileUpload(request);
    fileUpload.prepare();

    FileItem item = fileUpload.getFileItem();
    if (item.isEmpty()) {
        // If the file is empty, an exception should generally be raised.
    }
  
    String path = item.save();
  
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/plain");
    response.getWriter().write(path);
} finally {
    if (dextnj != null) dextnj.close();
}
In case of Spring MVC environment

In the Spring environment, you can set JKSpringExtensionUploadFilter instead of JKSpringExtensionUploadFilter in DD (web.xml).

The JKMultipartResolver setting can be omitted in the XML file responsible for DispatcherServlet setting.

# web.xml
<filter>
    <filter-name>extensionUploadFilter</filter-name>
    <filter-class>dextuploadjk.support.spring.JKSpringExtensionUploadFilter</filter-class>
    <!-- Setting parameters omitted -->
</filter>
<filter-mapping>
    <filter-name>extensionUploadFilter</filter-name>
    <!-- 
    Map the servlet or URL where you want Extension file-upload to be processed.
    <servlet-name>Serlvet name</servlet-name>
    <url-pattern>URL mapping</url-pattern>
    -->
</filter-mapping>

Temporary file information processed through the JKSpringExtensionUploadFilter filter can be received as a MultipartFile parameter in the method mapped to the Controller, and the final save operation can be performed by casting this object to the FileItem interface.

@RequestMapping(value = "/upload-extension.do", method = RequestMethod.POST)
public void upload(
    // In case of DEXTUploadX5 product, it is delivered with the name
    @RequestParam(value = "DEXTUploadX5_FileData") MultipartFile file, 
    HttpServletResponse response) throws IOException {
    
    // Cast to the FileItem interface.
    FileItem item = (FileItem)file;	
    
    if (item.isEmpty()) {
        // If the file is empty, an exception should generally be raised.
        // This is because DEXTUploadX5 does not send requests without files to the server.
    }  
    
    String path = item.save();
    
    response.setCharacterEncoding("UTF-8");
    response.setContentType("text/plain");
    response.getWriter().write(path);
}
For Spring Boot

In Spring Boot, you can register JKSpringExtensionUploadFilter as a bean.

@Bean
public FilterRegistrationBean<JKSpringExtensionUploadFilter> filterRegistrationBean(ServletContext context) {
    FilterRegistrationBean<JKSpringExtensionUploadFilter> fb = new FilterRegistrationBean<JKSpringExtensionUploadFilter>();
    fb.addInitParameter("tempRepository", "/files/temp");
    fb.addInitParameter("defaultRepository", "/files/store");
    fb.addInitParameter("autoMakingDirectory", "true");
    fb.addInitParameter("enableCleaner", "true");
    ...
    fb.setFilter(new JKSpringExtensionUploadFilter());    
    // upload-extension: Extension file-upload mapping path
    fb.addUrlPatterns("/upload-extension");
    return fb;
}

Once the filter is set, you can then process the temporary file in the controller's mapping method like in the Spring MVC environment.