Atitit. Implementation principle of file upload with progress bar and component selection and Best Practices summary O7

Source: Internet
Author: User
Tags call back http post server memory

Atitit. Implementation principle of file upload with progress bar and component selection and Best Practices summary O7

 

1. Implementation Principle 1

2. Principle of uploading large files: Using applet 1

3. New BP 2

1. Performance Improvement-split up small files for upload to avoid using too much memory at a time. 2

2. UUID or original file name: 2

3. Listener is frequently called 2

4. Combined with WZ easyui 2

4. Type Selection 2

5. uploadify: Yash JS + flash 3

6. commons-fileupload: 3

7. Cos tool O 'Reilly Company 3

8. Summary of large File Upload components 3

5. Implement UI Ajax + JQ + Bootstrap + commons-fileupload-1.2 4

6. # = Code 5

7. Refer to 6

 

1. Implementation Principle

 

If you want to display the progress bar, the file upload progress will be displayed in real time.
You need to use the ajaxj technology... up to an IFRAME blackhead ..
Working Principle
Actually, when processing the uploaded file, the upload progress information such as the total length of the file, the number of uploaded files, and the transfer rate is written into the session, the client browser
With Ajax technology, an independent process is created to obtain the upload progress information from the session and display it in real time. Ajax technology can obtain server data without refreshing new pages. Session
It can be seen as the server memory, which can be used to store a small amount of customer information.

 

 

Upload listener
Commons-fileupload version 1.2 supports upload listening. You only need to implement a listener and add it to the Upload Component. The listener needs to implement its progresslistener

 

Author: old wow's paw attilax iron, email: [email protected]

Reprinted please indicate Source: http://blog.csdn.net/attilax

 

2. Principle of uploading large files: Using Applet

 

3. Improved performance of the new bp1. it is used to split small files and upload them to avoid memory usage exceeding the limit.

You can configure chunk to split a large file into many small files and upload it. The background is merged into large files through PHP.

2. UUID or original file name ::

It is best to use the original file name, so that you can easily search for the... duplicate name problem on the server. You can use the suffix UUID to solve the... Chinese problem and convert it

3. Listener is frequently called

There is a problem. Because it is called very frequently. This will cause performance problems. A better
The solution is to reduce the number of calls. The following code adds a kilobytes instance attribute to the listener class. The default value is-1. When the pbytesread/1024 result changes (that is, when the unit is KB ), assign the new calculation result to kilobytes, and then
Update the upload progress. Otherwise, the upload progress is returned without doing anything. This reduces the number of information updates. If
When the file is very large, you can change the unit of KB to MB to further reduce the number of information updates.

4. Combined with WZ easyui

You cannot put a page blackhead, and Belle up form goes to maran ..

4. Selection

The commonly used multi-attachment upload controls are generally JS + flash, and support for JS + HTML, JS + Silverlight, and so on. However, none of them are applicable to JS + flash, after all, Flash Player is basically a browser and will be installed on the Internet. Therefore, the requirements for the client using the JS + flash plug-in are slightly simpler.

5. uploadify: Yash JS + flash6. commons-fileupload ::

The most widely used Java File Upload Component, Struts itself uses this package to process file uploads. The documentation is very detailed and easy to use.

Due to the limitations of fileupload, a progress bar cannot be displayed for each uploaded file. Only one progress bar can be displayed,

7. Cos tool O 'Reilly Company

It is said to be o'reilly, which surprised me. After all, o'reilly is famous for its book and has never heard of the open source contributions of this company.

I found a comparison document on the Internet to compare these three Upload components. Cos is much faster than fileupload and smartupload!

As the capacity increases, the performance of fileupload and smartupload decreases rapidly until the capacity reaches MB, smartupload is overwhelmed and crashed.

Download cos package (http://www.servlets.com/cos/index.html); Last Update Time is 2002 November 05! I was surprised to know that updating the COs package for a few days is the most common among open-source software, it makes me full of yearning!

But I really want to get the progress bar r ..

 

8. Summary of large File Upload components

 

Java Applet mupload

Mupload is a component that uses Java Applet technology to upload files using the standard HTTP protocol. After being digitally signed, the packaged component can be embedded into a webpage and can be uploaded to the server by a client. The package consists of a jar file and a JS file, use js to create the webpage component as needed to upload files! This component can be...

File Upload applet jfileupload

Jfileupload is a Java Applet used to upload files (non-open source) through the Web or FTP server. The server can be JSP/servlet, PHP, ColdFusion, CGI, ASP, etc. Supports upload progress bars, cancel buttons, and drag and drop

Multi-File Upload applet jupload

Jupload is a multi-File Upload applet. It can upload all files in the same directory at a time. In the client part of jupload management, you need to write a script for the server to manage the uploaded files when uploading using the HTTP protocol. using the standard http post command jupload, there are also a large number of Configuration Parameter session management languages to internationalize: over 20 languages FTP and... more information about jupload

 

5. Implement UI Ajax + JQ + Bootstrap + commons-fileupload-1.2

Bootstrap can be downloaded here: http://www.bootcss.com/

Two jar packages: commons-fileupload-1.2.jar

Commons-io-2.4.jar

 

 

 

6. # = Code


Example:
Public class uploadlistener implements progresslistener {

Private uploadstatus status; JavaBean that records the upload information

Public uploadlistener (uploadstatus status) {// Constructor

This. Status = status;
}
Public void Update (long bytesread, long contentlength, int items ){
Status. setbytesread (bytesread); the length of the data that has been read
Status. setcontentlength (contenlength); total length of the uploaded file
Status. setitems (items); number of files being saved


}
}
The prongresslistener interface has only one method: Update (long bytesread, long contenlength, int items ).
The byteread parameter indicates the number of uploaded bytes. contentlength indicates the total length of the uploaded file (if it is-1, the total length is unknown)
Items indicates the number of files being uploaded.
After a listener is added, the upload group will continuously call back the method and return the data when uploading files. With this data, you can know the progress of file upload and use the progress bar in real time.
Therefore, you need to save the data. In the above Code, the data is saved to an uploadstatus, which is a common Java Bean. The related code is as follows:
Public class uploadstatus {
Private long bytesread;
Private long contentlength;
Private int items;
Private longstarttime = system. currentimemillis ();

 

7. Reference

 

Upload a file with a progress bar-http://service.ap-south-1.htm

Java File Upload Component-open source software library-Open Source China Community .htm

Excellent Upload Component-cos-hingwu's column-blog channel-csdn.net.htm (smartupload fileupload, cos performance test, cos usage ,)

Java file upload with progress bar-blog channel-csdn.net.htm (jeigui zeush jeig)

Java File Upload Component Apache commons fileupload Application Guide (5) Listen to the file upload progress-Whistler-blogjava.htm (the listener is faulty. Because it is called very frequently. This will cause performance issues)

Apache commons fileupload implements file upload-Sub-scripts-51ctotechnical blog .htm (use JSP and sevlet up)

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.