Search code examples
javascriptjqueryajaxplupload

Plupload UploadProgress speed


i have this:

var uploader = $('#plupload').pluploadQueue();

uploader.bind('UploadProgress', function(up, file)
{
   speedLog(uploader);
});

function speedLog(uploader) {
    var speed = uploader.total.bytesPerSec;
    console.log(speed);
};

And it works, i can see the output in firebug, but is massive, my intentions are to submit "speed" trough ajax. I want speedLog() to be called every 5 seconds or so, how can i achieve this?

Thanks SR Query. I did this:

window.setInterval(
  function speedLog(uploader) {
    var uploader = $('#plupload').pluploadQueue();
    var speed = uploader.total.bytesPerSec;
    if(speed > 0)
    {
      console.log(speed);
    } else {
      clearInterval(ib);
    }
   }, 5000);

Looks good: http://imageshack.us/photo/my-images/221/speedt.png/


Solution

  • try this for jquery progress bar plugin.. you dont like plugin try this logic in another way.

    var ib;
    var timer_speed = 200; // 1000 = 1 second
    function progressBar_completeHandler(event, ui) {
       // what you want to do after completing the progress. do it here
    }
    $(function() {
        $("#progressbar").progressbar({value:0, complete:progressBar_completeHandler});
    });
    function start_timer(){
        val = $("#progressbar").progressbar("option", "value");
        ib=setInterval("increment_bar()",timer_speed);
    }
    function increment_bar() {
        $('#progressbar' ).progressbar( 'option', 'value', val+=1);
        if(val > 99){clearInterval(ib);}
    }