Js swfupload: Add upload progress bar implementation code

Source: Internet
Author: User

This article briefly introduces the implementation code of adding an upload progress bar to JavaScript swfupload. In fact, the solution is very simple. setStatus (\ "Uploading... \ "); Replace with progress. setStatus (\ "uploading (\" + percent + \ "%) Please wait... \ ");

Code

The Code is as follows: Copy code

Function uploadProgress (file, bytesLoaded ){

Try {
Var percent = Math. ceil (bytesLoaded/file. size) * 100 );

Var progress = new FileProgress (file, this. customSettings. upload_target );
Progress. setProgress (percent );
If (percent = 100 ){
Progress. setStatus ("File Uploaded successfully ");
Progress. toggleCancel (false, this );
} Else {
Progress. setStatus ("uploading (" + percent + "%) Please wait ...");
Progress. toggleCancel (true, this );
}
} Catch (ex ){
This. debug (ex );
}
}

Another method


Upload progress setting event

The Code is as follows: Copy code

Function uploadProgress (file, bytesLoaded ){

Try {

Var percent = Math. ceil (bytesLoaded/file. size) * 100 );

Var progress = new FileProgress (file, this. customSettings. upload_target );

Progress. setProgress (percent );

If (percent = 100 ){

Progress. setStatus ("the upload is complete and the memory is being released. please lock the mouse and do not touch it. Saving ......");

Progress. toggleCancel (false, this );

// Jump to the uploaded webpage

Refresh ();

}

// Display the upload information

Else {

Progress. setStatus ("Uploading ...... ‖ uploaded: "+ (bytesLoaded/(1024*1024) +"/"+ file. size + "" + percent + "% 』");

Progress. toggleCancel (true, this );

}

} Catch (ex ){

This. debug (ex );

}

}

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.