yeah I've run into the same thing recently. In my case, I have an
uploader application that allows the user to upload multiple files at
once. It allows the user to keep adding items to be uploaded. Problem
was it was failing silently with no Complete Event being triggered.
Checked the server for this and it seems it isn't receiving a request
from the server. So....

Listen for the progressEvent & when the bytesLoaded == bytesTotal,
start a timer to see how long before the Complete event is fired. If it
times out, then reload the file. If not then reset the timer. Here's
where I place the timer in the progress event handler:

private var timerActive:Boolean = false;
/* set to 7 seconds but you can set your length as you like */
private var myTimer:Timer = new Timer(7000, 1);

private function uploadProgress(event:ProgressEvent):void
{

if(event.bytesLoaded == event.bytesTotal)
{
if(!timerActive)
{
timerActive = true;
myTimer.addEventListener(TimerEvent.TIMER,intermedUpload);
myTimer.start();
}

private function intermedUpload(evt:*):void
{
if(!notServerError)
reUploadFile();
else
{
displayFileError();
myTimer.removeEventListener(TimerEvent.TIMER,intermedUpload);
myTimer.reset();
timerActive = false;
}

private function reUploadFile():void
{
timerActive = false;
...
....
uploadFile();

}


ps. some of this is psuedocode.
hope that makes sense
cheers
erick
--- In [email protected], "limhy0306" <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> Currently, I am trying to upload a file to multiple URLRequest.
> -> FileReference.upload(URLRequest) is called several times; one
> after another when the upload has finished for the previous one.
>
> However I found that the 2nd time the upload occurs, the
> Event.COMPLETE is not getting triggered; even though the uploading
> of the file is successful!
> In the code below:
> the 1st upload always trigger the Event.COMPLETE
> but the 2nd upload fails to trigger the Event.COMPLETE!
>
>
> Has anyone solve this before?
>
> Below are my codes:
>
> <?xml version="1.0" encoding="utf-8"?>
> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
> layout="absolute" creationComplete="initApp()">
>
> <mx:Script>
>  <![CDATA[
>   import mx.events.*;
>   import flash.net.*;
>   import mx.controls.Alert;
>      import mx.utils.ObjectUtil;
>      import mx.utils.URLUtil;
>
>   private var fileRef:FileReference;
>   private var request:URLRequest;
>   private var urlVars:URLVariables;
>   private var currCount:int=0;
>
>   private function initApp():void
>   {
>
>   }
>
>   private function handleSelect(event:Event):void
>   {
>       trace("Select: "+event);
>    doUpload(2);
>   }
>
>   private function handleComplete(event:Event):void
>   {
>    trace("Complete: "+ currCount);
>
>
>    // Upload to another id when the 1st upload
> has finished
>    if(currCount < 2)
>    {
>     doUpload(1);
>    }
>
>   }
>
>
>   private function onUploadFile():void
>   {
>    fileRef = new FileReference();
>    fileRef.addEventListener(Event.SELECT,
> handleSelect);
>    fileRef.addEventListener(Event.COMPLETE,
> handleComplete);
>    fileRef.browse();
>   }
>
>
>                // Calls the FileReference.upload
>                // Only difference between multiple uploads is
>                // the id parameter.
>   private function doUpload(id:int):void
>   {
>    currCount++;
>
>    // Set the parameter to the perl script
>    urlVars = new URLVariables();
>    urlVars.action = "testmgr";
>    urlVars.op = "upload_test";
>             urlVars.id = id.toString();
>             urlVars.info="Test Script";
>             urlVars.name=fileRef.name;
>    request = new URLRequest
> ("http://192.168.15.190/perl/ecpcons.pl";);
>    request.data = urlVars;
>    request.method = URLRequestMethod.POST;
>
>    fileRef.upload(request);
>   }
>
>
>  ]]>
> </mx:Script>
>
>  <mx:Panel x="124" y="95" width="250" height="200"
> layout="absolute" title="Upload Files to Server">
>   <mx:Button x="67" y="110" label="Upload a file"
> id="btnUploadFile" click="onUploadFile()" enabled="true"/>
>   <mx:Text x="30" y="35" id="txtMessage"/>
>  </mx:Panel>
>
> </mx:Application>
>


Reply via email to