FileReference.upload non asynchronous?

I'm a bit of a flex noob, but I couldn't find this question asked anywhere, or a proper workaround. I'm quite used to GET/POST and web interactions, but I'm new to working in mxml's and such. See function below.

private function uploadFileSelect(event:Event):void 
{
    var uploadURL:String = Application.application.parameters.UploadURL;
    var urlStr:String = ExternalInterface.call('window.location.href.toString');
    var queryMap:Object = getQueryParams(urlStr);

    var request:URLRequest = new URLRequest(uploadURL);
    var urlVars:URLVariables = new URLVariables();
    urlVars.appid = queryMap.appid;
    urlVars.str = queryMap.str;
    request.method = "POST";
    request.data = urlVars;

    uploadFileRef.upload(request);              
}

Essentially, this works perfectly for what I need, with one exception. The final call to .upload is asynchronous, so I stay on the current page, but it calls the upload URL in the background. I want it to act like a form and actually navigate TO the upload URL with the POST data. I feel like this should be a simple solution, but I was kind of thrown the task of working on someone else's flash code and need a little advice.

Thanks in advance!

Answers


Because it is asynchronous, you cannot achieve redirect from the UI like you do in Html form. As a work around you can add listeners to the uploadFileRef

uploadURL = "someurl";

uploadFileRef.addEventListener(Event.complete, function(e:Event){
  navigateToURL(new URLRequest(uploadURL),'_self')
});

navigate url will tke you to the target url. I do not know how you will get the uploadURL, i'm assuming it is the url at which you have uploaded the file to.


Need Your Help

OOP: Which class should own a method?

java c++ oop class-design uml

I’m having trouble understanding how classes relate to their methods. Is a method something that the object does, or something that’s done to it? Or is this a different concept entirely?