Flash FileReference.browse Problems on Linux

When developing flash applications using flex, you can use flash.net.FileReference to upload files from the client to the server. Lately, we have been having problems with this on linux, and through a flex bug report on FileReference.browse Adobe helped me out. The problem was, that the flashplayer did not upload any file, the first time the browse method was called, after a browser restart. Same problem existed in the standalone player.

As the bug report on FileReference.browse says, it seems to be a problem with the garbage collector of the AVM2. So, simply moving the FileReference instance variable outside the method and onto the class instance level, made the problem go away.

This code failed:

private function upload() : void {
  var fileRef:FileReference = new FileReference();
  fileRef.addEventListener(Event.SELECT, function selectHandler(event:Event) :void {
    var uploadUrl : String = "http://localhost:8080/open/upload";
    var request:URLRequest = new URLRequest(uploadUrl);
    try {
      fileRef.upload(request);
    } catch (error:Error) {
      Alert.show("Unable to upload file.");
    }
  });
  try {
    var success:Boolean = fileRef.browse();
  } catch (error:Error) {
    Alert.show("Unable to browse for files.");
  }
}

While this code works:

private var fileRef:FileReference;
private function uploadBilag() : void {
  fileRef = new FileReference();
  fileRef.addEventListener(Event.SELECT, function selectHandler(event:Event) :void {
    var uploadUrl : String = "http://localhost:8080/open/uploadbilag";
    var request:URLRequest = new URLRequest(uploadUrl);
    try {
      fileRef.upload(request);
    } catch (error:Error) {
      Alert.show("Unable to upload file.");
    }
  });
  try {
    var success:Boolean = fileRef.browse();
  } catch (error:Error) {
    Alert.show("Unable to browse for files.");
  }
}

Just wanted to let you all know, if you run into the same problem.

Actually, it seems like FileReference.browse has other problems too. The complete event seems to always fire, even though the upload fails, and it never fires ioError or httpStatus events, even though the upload fails. Oh well… :-(

December 30, 2007 В· polesen В· 2 Comments
Tags: , ,  В· Posted in: Programming

2 Responses

  1. m.j.milicevic - January 17, 2008

    If you happen to work with FMS, there’s similar issue with NetStream/Connection stuff: you need to define netstream outside of your method (as a object instance), otherwise it’ll be garbage collected and when your method finishes, you get frozen stream (actually webcam is not streaming anymore).
    I think that something similar happens with filereference, so, maybe linux player is right?

  2. Flash saves in Windows, not in Linux, FileReference.save() | Q&A System - January 2, 2012

    [...] out belonging in the direction of purpose in to the school level, hoping to keep away from a recognised bug and also to sustain a reference in the direction of document alive outside the function. However, [...]