tags:

views:

39

answers:

2

I'm attempting to upload a file using FileRef and a php script. The file uploads and it definitely returns a test string ( I can see it with a web debugger).. but I can't grab that string in my flex app. I am using a DataEvent listener and a COMPLETE listener. Still no result.

What am I doing wrong here?

fileRef.addEventListener(DataEvent.UPLOAD_COMPLETE_DATA, onFileResponse);
fileRef.addEventListener(Event.COMPLETE, fileRef_complete);

private function fileRef_complete(evt:Event):void{

     trace("COMPLETE");
     trace(evt.target.data);

    }

private function onFileResponse(event:DataEvent)
    {
     message.text = "HELLO";
     trace("UPLOAD COMPLETE = " + event.data);


    }
A: 

Is your issue that the events are not being fired, or that data field is empty when the events are fired?

If the former, is the server returning HTTP code 200? That's the only direct specification I see in the FileReference docs.

If the latter, I don't think it's expected for the data field to be populated on an upload() call:

data:ByteArray [read-only]

The ByteArray object representing the data from the loaded file after a successful call to the load() method.


Edit:

Does the FileReference go out of scope before the call is complete--that will cancel the transaction from the Flash end (though the call may still complete on the web end).

How are you calling FileReference.upload()? I assume that's not the issue if your web debugger shows success, but it may be of interest.

Michael Brewer-Davis
the events aren't being fired at all. Even a simple trace isn't firing on the event.
Brent
A: 

this is how i'm calling file upload:

fileRef.upload(urlReq, "Filedata", false);

It shouldn't be going out of scope, it's in the same mxml doc, but maybe I'm missing something.

brent
Perhaps if you edited the main question with a full example (stripped down to just what's needed to replicate)?
Michael Brewer-Davis
I figured it out, was just calling everything in the wrong order. As soon as I put the event listeners after the file was selected then it worked fine.
Brent