6

I am uploading a file to a server using a multipart URLLoader. I am able to upload the file fine. I have tried to listen to the progress event on the URLLoader but it only fires at the very end of the upload. How do I get the progress event more consistently through the upload?

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
asawilliams
  • 2,908
  • 2
  • 30
  • 54

1 Answers1

2

Have a progress-bar:

<mx:ProgressBar width="100%" id="progBar" mode="manual" />

Register a progress event handler:

refUploadFile.addEventListener(ProgressEvent.PROGRESS, onUploadProgress);

And handle it:

private function onUploadProgress(event:ProgressEvent):void {
        var numPerc:Number = Math.round(
            (Number(event.bytesLoaded) / Number(event.bytesTotal)) * 100);
        progBar.setProgress(numPerc, 100);
        progBar.label = numPerc + "%";
        progBar.validateNow();
}

If your files are small, it is normal to not receive many events. Try with bigger files.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 1
    this is exactly what I did. The problem is still that the event is only fired at the very end of the upload. – asawilliams Sep 21 '10 at 15:22
  • perhaps your files are very small? Try with a bigger one. – Bozho Sep 21 '10 at 15:26
  • ive been trying with a file size of 1.6 MB, it takes about 20 secs to complete. – asawilliams Sep 21 '10 at 16:17
  • ok. what version of flex then? See, there is a lot of information unknown to me. (Btw, the above code works fine for me, so I'm surprised it doesn't for you) – Bozho Sep 21 '10 at 16:30
  • 1
    im on 3.5sdk. The key difference is the use of multipart. If it was not multipart then your code would work fine. – asawilliams Sep 21 '10 at 17:38
  • and why do you need it to be multipart? – Bozho Sep 21 '10 at 18:01
  • 3
    UrlLoader fires ProgressEvent just for download operation, so itf fires the first event when all the file is uploaded and you are downloading the page. You can't use it to monitor upload – wezzy Oct 21 '10 at 14:45