Webuploader Upload Tool

Source: Internet
Author: User

http://fex.baidu.com/webuploader/getting-started.html# Show User Selection

HTML section

Prepare the DOM structure first, including the container that holds the file information, the selection button and the upload button three parts.

<divid= "uploader" class= "Wu-example" > <!--used to store file information--<div id=  "thelist" class= "uploader-list" ></div > <div class= "Btns" > <div id= "picker" > Select File  </div> <button id= "ctlbtn" class=< Span class= "s" > "btn Btn-default" > start uploading </button> </ Div></DIV>            
Initializing the web Uploader

For specific instructions, take a look at the comments section in the code.

var uploader = webuploader.< Span class= "NX" >create ({//swf file path swf: base_url +  '/js/uploader.swf ' // The file receives the service side. server:  ' http://webuploader.duapp.com/server/fileupload.php ' Span class= "P", //Select the File button. Optional. //internally based on the current run is created, either the INPUT element or flash. pick:  ' #picker '  //does not compress image, Default if it is JPEG, the file will be compressed before uploading! resize: false      
Show User Selection

Because Webuploader does not handle UI logic, it needs to be monitored for fileQueued events.

When a file is added to the queueUploader.On ( ' filequeued ' function (file ) { $list . Append ( ' <div id= "' + file.< Span class= "NX" >id +  "class=" item "> ' +  < h4 class= "Info" > ' + file. Name +  ' +  ' <p class= ' state ' > Wait to upload ...</p> ' +  </div> ' );    
File Upload Progress

On the file, the Web uploader dispatches the uploadProgress event, which contains the file object and the current upload progress of the file.

Create a progress bar in real-time display during file upload.Uploader.On(' Uploadprogress ',function(File,Percentage){Var$li=$(‘#‘+File.Id),$percent=$li.Find('. Progress. Progress-bar ');Avoid duplicate creationIf(!$percent.Length){$percent=$(' <div class= ' progress progress-striped active ' > '+' <div class= ' Progress-bar "role=" ProgressBar "style=" width:0% ">"+' </div> '+ ' </div> ').  AppendTo( $li ).  Find('. Progress-bar '); } $li.  Find(' p.state ').  Text(' in-upload '); $percent.  CSS( ' width ', percentage *  + '% ' );});     
File success, failure handling

A file upload failure dispatches an uploadError event, and the event is dispatched successfully uploadSuccess . Regardless of success or failure, events are triggered after the file has been uploaded uploadComplete .

Uploader.On(' Uploadsuccess ',function(File){$(‘#‘+File.Id).Find(' P.state ').Text(' uploaded ');});Uploader.On(' Uploaderror ',function(File){$(‘#‘+File.Id). Find(' p.state ').  Text(' upload error ');}); uploader.  On( ' uploadcomplete ', function( file ) { $( ' # '+file . ID ). Find('. Progress ').  FadeOut();});                
Image upload

Webuploader Upload Tool

Related Article

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.