title: AS3 Upload speed test
body: <p><br>
  I'm making an speedtest on AS3. And got such a problem.<br>
  I'm using <code>URLLoader( )</code> in my test, and for download test it work very good, but for uploading test i got some troubles. I'm sending some binary data to my php-script, and checking the <code>progress_event</code> to get <code>bytesLoaded</code>, to calculate current speed, but the event is not dispatching, only <code>complete_event</code> appears when thi whole file is sent. So how can I determine the speed by bytes-sending process?<br></p>
  
  <p>P.S. I can't use <code>fileReference</code>, cause I'm using my tests one-by-one and can't make users click in filebrowse() dialog.</p>
  
  <p>Thx. </p>
  
  <pre><code>        public function startme( ):void {
  
               _startTime = ( new Date( ) ).getTime( );
  
          var req:URLRequest = new URLRequest();
          req.url = "http://smart.t3a.ru/speedtest/test.php";
          req.contentType = 'application/octet-stream';
          req.method = URLRequestMethod.POST;
          req.data = Obj;
  
          //req.requestHeaders.push( new URLRequestHeader( 'Cache-Control', 'no-cache' ) );
  
          _loader = new URLLoader();
          _loader.dataFormat = URLLoaderDataFormat.BINARY;
          _loader.addEventListener(Event.COMPLETE,uploadComplete);
          _loader.addEventListener(ProgressEvent.PROGRESS, uploadProgress );
          _loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, onstatus);
          _loader.addEventListener(IOErrorEvent.IO_ERROR, eIOError);
          _loader.load(req);
  
  
      }
  
      private function onstatus(event:HTTPStatusEvent):void
      {
          trace(event);
      }
      private function eIOError(event:IOErrorEvent):void
      {
          trace(event);
      }
  
      private function uploadComplete( e:Event ):void
      {
          var endTime:Number = ( new Date( ) ).getTime( );
          var totalTime:Number = ( endTime - _startTime ) / 1000;
  
          var totalKB:Number = Obj.length * 8 / 1024;
          //_speed = totalKB / totalTime;
  
          if (debug)
          {
              trace( "U total time: " + totalTime + " total KB: " + totalKB + " speed: " + speed + "KBps" );
          }
  
          dispatchEvent( e );
      }
  
      private function uploadProgress( e:ProgressEvent ):void
      {
          var endTime:Number = ( new Date( ) ).getTime( );
          var totalTime:Number = ( endTime - _startTime ) / 1000;
          if (totalTime &gt; 1)
          {
              var totalKB:Number = e.bytesLoaded * 8 / 1024;
              _speed = totalKB / totalTime;
  
              if (debug)
              {
                  trace( "u total time: " + totalTime + " total KB: " + totalKB + " speed: " + speed + "KBps" );
              }
              dispatchEvent( e );
  
          }
          if (totalTime &gt; 7)
          {
  
              var ec:Event = new Event(Event.COMPLETE);
              _loader.dispatchEvent(ec);
              _loader.close();
          }
      }
  </code></pre>
  
  <p><strong>UPD</strong>
  My php script:</p>
  
  <pre><code>    &lt;?
      $postdata = file_get_contents("php://input");
      file_put_contents("inp.bin",var_export($postdata,true));
      echo "Done";
      ?&gt;
  </code></pre>
  
  <p>Yes it's small, but i realy don't need the data, i need to check how fast is it uploaded.</p>
  
  <p><strong>UPD 2</strong></p>
  
  <p>So, after reading all the answers, comments and googling for hours, i probably got the solution, but it is made in some different way, than i wish at the beginning. Anyway TYVM all, i'll post the solution shortly.</p>