Fun with code (since 2006)

FileReference – A petition for Astro !

12.22.07 Posted in Actionscript 3, Others by

André Michelle posted a few days ago a petition concerning the onSoundComplete event. This gave me an idea concerning the API we have currently in the Flash Player 9.

One of the most disappointing thing we have when playing with bytes in the Flash Player 9 is the FileReference API. Let's say you call the FileReference.browse() method to select a file.

Once selected, you have no way to get a ByteArray from it directly.

Of course you have the following solution :

First, you have to upload the file to your server, then you have to download it with the class as a binary file (URLLoaderDataFormat.BINARY), and then you'll get the bytes.

This means that for any Flash online image editing application, you will have to upload your bitmap first, and then download it before having fun with the application. I would like to introduce a new method in the AlivePDF library so that you can embed any image stream easily. The current Flash Player doesn't facilitate that.

Same limitation with the GIFPlayer library and ASZip.

Now, even worse.

There is no way to save a generated ByteArray on the hard disk through the FileReference API. Once again, you will have to upload it, and then ask to a server side script to spit it out back to the browser with appropriate headers so that it shows a download box window.

But guess who does allow all of this ? ;)

Here is how you would get the bytes from a selected file in Silverlight 1.1 with the OpenFileDialog class :

Stream fileStream = browseDialog.SelectedFile.OpenRead();
byte[] funkyBytes = new byte[fileStream .Length];
fileStream.Read(funkyBytes, 0, (int)fileStream.Length);

The final release of Silverlight 1.1 will also include a SaveFileDialog class. This should allow us to save runtime streams locally through a save-as dialog window.

As would say André, please leave a comment. Let's bring that in the Flash Player 10, that would rock.

Please Adobe ;)

Update : This feature is available in the Flash Player 10 ;)

59 Responses to “FileReference – A petition for Astro !”

  1. Vijay Chakravarthy says:

    I was faced with a similar problem, and looked around and found this post. Which also got me thinking — wouldnt it be possible (in cases where someone has both silverlight and flash 9 installed) to do this via silverlight to flex communication via the browser?

  2. Jensa says:

    Yeah. Good point!

    (and congrats on the new job!)


  3. +1 here as well!
    Our Adobe flash apps would help us grow with a feature like this.

  4. collin says:

    +2 here (my partner wants this BADDD)

  5. CantGetRight says:

    This has my vote!

    Regarding the security… I don’t see how this could be a problem. Whenever a user saves a file, he/she is at risk of downloading something corrupt. Be it downloaded or straight from the player.

  6. Rogier says:


    I can see why Adobe currently doesn’t allow local files to be accessed at all, but it should at least be a security setting.
    This way we can ask a user for permission (allow/always allow), similar to access of the camera/microphone.

    Also, I think it should not only be limited to the FileReference; I’ve been experimenting with drag & drop uploads using a combination of javascript and Flash, I managed to find a way to detect an image drop on the browser using javascript and I seriously would like to be able to tell Flash to load this particular image so I can manipulate it (resize, crop, rotate) it _before_ I upload it from a ByteArray.

  7. Thibault Imbert says:

    Hi Rogier,

    it seems like Adobe listened to this request. Such a feature is available in Astro (Flash Player 10)

    Check this post :)

  8. [...] in the NetStream class you have to send it to a server and load it again, damn, do you remember a similar story [...]

  9. [...] on guys ! We raised our voice for FileReference, if you would be happy having such a feature, vote for it ! Post a comment | Trackback [...]


Leave a Reply

Open Sort Options

Sort comments by:
  • * Applied after refresh
Fun with code since 2006.