0 Replies Latest reply on Feb 10, 2009 9:32 AM by wabisabi2004

    File upload complete event fails silently

    wabisabi2004
      Hello,

      Has anybody seen FileReference class not calling handler for Event.COMPLETE? From time to time I run into this trouble. FileRefernce seems to call ProgressEvent.PROGRESS fine. Anyway, here is the code:

      quote:


      var fileReference : FileReference = object as FileReference;
      fileReference.addEventListener(Event.COMPLETE, completeHandler);
      fileReference.addEventListener(ProgressEvent.PROGRESS, progressHandler);
      fileReference.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSecurityFailure);
      fileReference.addEventListener(HTTPStatusEvent.HTTP_STATUS, handleHttpFailure);
      fileReference.addEventListener(IOErrorEvent.IO_ERROR, handleIoFailure);

      var request : URLRequest = new URLRequest(getUploadUrl());
      try {
      fileReference.upload(request);
      } catch (error : Error) {
      log.info("Error performing the upload " + error);
      dispatchFailureEvent(error.errorID + ": " + error.name, error.message);
      }



      and here are the handlers:

      quote:


      private function handleIoFailure(event : IOErrorEvent) : void {
      log.warn("IO Failure " + event);
      dispatchFailureEvent("I/O Error", event.text)
      }

      private function handleHttpFailure(event : HTTPStatusEvent) : void {
      log.warn("HTTP Failure " + event);
      dispatchFailureEvent("HTTP Error: " + event.status, ObjectUtil.toString(event));
      }

      private function handleSecurityFailure(event : SecurityErrorEvent) : void {
      log.warn("Security Failure " + event);
      dispatchFailureEvent("Security Error", ObjectUtil.toString(event));
      }

      private function dispatchFailureEvent(cause : String, message : String) : void {
      var event : FaultEvent = new FaultEvent("failure");
      event.cause = cause;
      event.message = message;
      dispatchEvent(event);
      }

      private function progressHandler(event : ProgressEvent) : void {
      log.debug("Progress updated: " + event);

      // complete event doesn't get dispatched, where there is an upload delays
      // (for example if user must enter the password for NTML authentication)
      if (event.bytesLoaded == event.bytesTotal) {
      log.debug("### Transferred all bytes - {0} out of {1}", event.bytesLoaded, event.bytesTotal);
      // completeHandler(null);
      }
      }

      private function completeHandler(event : Event) : void {
      log.debug("Dispatching competion event. Triggered by " + event);
      dispatchEvent(new Event("completion"));
      }



      Finally, here is the log:

      quote:


      2/10/2009 11:33:18.973 [INFO] >>> File upload exists - signalling upload requirement <<<
      2/10/2009 11:33:18.989 [DEBUG] components.managers.FileUploadManager Uploading [object FileReference]
      2/10/2009 11:33:19.067 [DEBUG] components.managers.FileUploadManager Progress updated: [ProgressEvent type="progress" bubbles=false cancelable=false eventPhase=2 bytesLoaded=258065 bytesTotal=258065]
      2/10/2009 11:33:19.067 [DEBUG] components.managers.FileUploadManager ### Transferred all bytes - 258065 out of 258065



      That's all - at this point poor file upload hangs. It's particularly bad in FF - it crashes the browser. Do you know if I am doing something wrong here, or it that's a bug?

      As a side note, I gotta use NTLM authentication for file uploads, can the missed event be related to that? There are a few posts that seem to be related to this issue as well:

      http://www.adobe.com/cfusion/webforums/forum/messageview.cfm?forumid=60&catid=585&threadid =1404733

      and this

      http://bugs.adobe.com/jira/browse/FP-201

      However, what puzzles me the most, when I try to play with it on localhost, it works just fine! The problem shows up when the app is deployed in the DEV environment. Security issue in Flex? What's more important IE works just fine with DEV. What's up?!? Write Once - Debug Everywhere? I think I heard this one before.