Introduction and comparison of Smartupload and Commons-fileupload

Source: Internet
Author: User
Tags comparison file size file upload ftp file save file
Comparison
Web file upload is probably one of the most common functions of website construction, I need to implement the file upload function in the project development almost. Some time ago, I collected some upload components. This article will describe how these components are used and compare their pros and cons.

One, smartupload components.

I think as long as a file upload friends know this component, I know people who use the most is also it! When I first came to the company, the company also used the Smartupload, this component is a good choice when uploading relatively small files. Here is an example of what to use:

<%@ page contenttype= "text/html;charset=gb2312"%><%@ page import= "java.sql.*"%><%@ page import= " com.jspsmart.upload.* "%>

<%  //materialized upload bean    smartupload mysmartupload=new smartupload ();   // Initialization     mysmartupload.initialize (PageContext);    //Set maximum upload value, note: If there is a problem set up in this Assembly!    mysmartupload.setmaxfilesize (500 * 1024*1024);    //Upload file     mysmartupload.upload ();  //Loop get all uploaded files    for (int i =0;i<mysmartupload.getfiles (). GetCount () i++) {  //Get uploaded files    com.jspsmart.upload.File MyFile = Mysmartupload.getfiles (). GetFile (i);   if (!myfile.ismissing ())     {  / /get the filename of the uploaded file     String myfilename=myfile.getfilename ();   //get filename without suffix      string  suffix=myfilename.substring (0,myfilename.lastindexof ('. '));    //Get suffix name     string  ext= mysmartupload.getfiles (). GetFile (0). Getfileext ();      //Get file size       int fileSize=myfile.getsize ();   //save path     String aa=getservletcontext (). Getrealpath ("/") + "Jsp\\";    string trace=aa+myfilename;   //Get other parameters     string explain= (string) mysmartupload.getrequest (). GetParameter ("text");    string send= (String) Mysmartupload.getrequest (). GetParameter ("send");   //Save file on server-side     Myfile.saveas ( trace,mysmartupload.save_physical);   %>

However, the use of smartupload upload large files, or multiple files may occur when the CPU or memory consumption is too high a problem. And: Only reboot the container to return to normal! That's why I finally gave up using Smartupload.

Second, commons-fileupload components

This component is the component I am using now, download address: http://jakarta.apache.org/site/downloads/downloads_commons-fileupload.cgi, the package contains the API documentation.

Examples of using this component:

<%@ page language= "java" contenttype= "TEXT/HTML;CHARSET=GBK"%><%@ page import= "java.util.*"%><%@ page Import= "org.apache.commons.fileupload.*"%>
From the above program can be seen, the component upload can use a place to store temporary files, after the upload finished directly to write the file past. This will not consume too much memory! And the component upload large files when the efficiency is not low Oh!

In both of these comparisons, I chose the latter, because I often uploaded files larger than 10M in my project, and the server almost collapsed when I used the former.

However, now that I have not used these two components, because the HTTP way file efficiency is always very low, we are now using the Web implementation of FTP file upload, I will write in the next article how I implemented in the project.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.