Flex Pasta » 2010 » February
A hand full of bugs have been field with Adobe’s Flash Player regarding problems uploading with Firefox.
https://bugs.adobe.com/jira/browse/FP-78
https://bugs.adobe.com/jira/browse/FP-1044
https://bugs.adobe.com/jira/browse/FP-419
https://bugs.adobe.com/jira/browse/FP-201
https://bugs.adobe.com/jira/browse/FP-568
There have also been plenty of posts describing the problem.
http://sethonflex.blogspot.com/2007/10/flex-and-filereferenceupload-using.html
http://thanksmister.com/index.php/archive/firefox-flex-urlrequest-and-sessions-issue/
http://stackoverflow.com/questions/351258/how-do-i-make-flex-file-upload-work-on-firefox-and-safari
In Flash 9, there is really no good way around this problem. However, in Flash 10 / Flex 4, an enhancement to flash.net.FileReference makes it possible to read the contents of a file before it is uploaded. Meaning that the file can be uploaded in different ways then can be done in Flash 9. The following example shows how easy file uploading can be and is not tied to SSL, Firefox, IE, Chrome, etc. This method is using Java server side with BlazeDS, but could be modified to work with other setups.
First, look at the application file.
<?xml version=”1.0″ encoding=”utf-8″?>
<s:Applicationxmlns:fx=”http://ns.adobe.com/mxml/2009“ xmlns:s=”library://ns.adobe.com/flex/spark“ xmlns:mx=”library://ns.adobe.com/flex/halo” minWidth=”1024” minHeight=”768“>
<s:layout>
<s:VerticalLayout/>
</s:layout>
<fx:Declarations>
<!–
Place non-visual elements (e.g., services, value objects) here –>
<s:RemoteObject id=”upload” destination=”uploadService” endpoint=”http://localhost/Context/messagebroker/amf“/>
</fx:Declarations>
<fx:Script>
<![CDATA[
private var fr:FileReference = new FileReference();
private function test():void
{
fr.browse();
fr.addEventListener(Event.SELECT, selected);
fr.addEventListener(Event.COMPLETE, complete)
}
private function selected(event:Event):void
{
fr.load();
}
private function complete(event:Event):void
{
var byteArray:ByteArray = fr.data;
upload.uploadFile(byteArray);
}
]]>
</fx:Script>
<s:Button label=”Upload” click=”test()”/>
</s:Application>
Notice the fr.load(); This will actually load the file and make it’s contents available to us in the code. The complete handler than takes those contents as a byte array and calls the remote “uploadService” passing in that byte array. Here is the simple Java code for the service method “uploadFile”:
public void uploadFile(byte[] file)
{
// Do something here to save the file
}
It is that easy in Flash 10. By allowing access to the file, the upload process is quick and painless.