1 Reply Latest reply on Dec 20, 2009 1:18 AM by pauland

    Countdown of file size?






      I have made a multiple fileuploaid in Flex 3, this works perfect. Now I want to add some features to the app. How can I get the total amount mb a user like to upload, and how can i make a countdown froom this amount. Let say a user will upload 5 files and the total size is 3 mb. I want to show the user the total amount and a countdown that shows how much it is left to upload. I have tried this way:


       function selectHandler(event:Event):void
      var fileList:Array = fileReferenceList.fileList;
                     totalSize = 0;
                     totalSize2 = 0;
                     totalNumberOfFiles = 0;
                     totalLoaded = 0;
      for (var i:Number=0; i<fileList.length; i++)               {
      var file:FileReference = FileReference(fileList[i]);                    
      var fileSizeToMB:Number = Math.round(file.size /1048576 * 100) / 100;                    totalSize += fileSizeToMB;
                          totalSize2 += file.size;
                          totalNumberOfFiles ++;
                          lblProgress.text = 
      "Totalt att ladda: " + totalSize.toString();                    lblTotalFiles.text = 
      "Antal filer: " + totalNumberOfFiles;                    arrayCollection.addItem({name:file.name, size:fileSizeToMB, object:file})


      This way I get the total amount correct, I have also declared the variables on top of the page. I have tried thios way to do the countdown:

      var file:FileReference = FileReference(event.target);             totalLoaded = totalSize2 - event.bytesLoaded;        
                   lblLoadedSoFar.text = totalLoaded.toString();
       function progressHandler(event:ProgressEvent):void {

      This works fine when the user only upload one file, but not when the user uploads multiple files.


      Lastley, is it possible to get the transfer speed in as3? If it is, how do I do? I also would like to add how much time there is left of the upload and how long the upload have been active. I'm usinbg Flex 3 and as3.

        • 1. Re: Countdown of file size?
          pauland Level 4

          I don't have time to write an example solution, but here are some pointers.


          If there are multiple files involved you will need to track the download of each file, not just the one that issues the event at a given time, so I would probably store references to the files that are uploaded (perhaps in an array - push thefile reference onto the array when uploading a file), so whenever an event is triggered I can check the bytes downloaded for all the files, not just the current one.


          For the transfer speed, the only way I know to try and estimate the transfer speed is to time the download and then as the file is downloading, estimate the speed by dividing the data downloaded by the time since the transfer began.