FileReference Mixing UI with RPC

Some of you may think I spend my life working with FileReference as I go on about it so much. I’ve gone on about how extremely easy to use it is, until today.

If you want to make up little Apps, FileReference it is perfect for the job and you wouldn’t run into this problem (in fact you’d probably think the way I would like to see it implemented would make things a lot more awkward for you), but if you were to build anything bigger seperating out your view components, model, controller and RPC etc you will run into a problem.

The FileReference object mixes user interaction (FileReference.browse() FileReference.download()) with RPC (FileReference.upload()) which really complicates things.

For instance I have a UIComponent to let users upload files. I could either locate my FileReference object inside this component, but this component shouldn’t know anything about the server side script to target in the upload process, this data should be stored and the method carried out within my Service class. I don’t want any RPC logic in my UIComponent.

I could create the FileReference object within my Service. This means that when the user wants to browse, upload or download with FileReference I have to dispatch an event from my UIComponent which gets picked up in my Controller. This tells my Delegate class to do the correct action, which then invoked my service. This feels is fine for the upload method but seems hard work just to get a browse window to open or download a file.

Another alternative (which is the one I’m going to go with for now) is to create my FileReference object in my UIComponent. The browse and download methods can then be invoked directly. Once the user selects upload an event dispatched that the Controller picks up. The UIComponent then has a getter for the FileReference object that has been populated, and this can be passed to my Delegate and then onto the Service which can complete the upload process. Because my UIComponent is listening to the FileRefence object being acted upon it can listen to its events directly.

What would have been nice to see in AS 3.0 is the FileReference object broken down something more like what Java has (which i know very little about).

FileChooser
Lets the user choose a file/files to upload or a directory to save in. It would return a FileReference object.
FileReference
Returned by FileChooser and stores information about the file/files to upload or the directory to save in.
FileService
Requires a FileReference object to complete the upload/download process

This approach looks a lot cleaner and easier to use in large framework situations albeit a bit more awkward if you want to do a quick upload/download. Obviously its far too late in the game for this to happen.

8 Responses to “FileReference Mixing UI with RPC”

  1. johannes says:

    i agree browsing for the file is a ui task and should not be on the service layer.
    i especially like the breakdown you suggest for how the file uploading should work.

  2. Jay says:

    Is there a way to capture the file reference the way that it stands right now? I can get the file.name but not the path to the file. Also can this be used locally instead of to upload to a server? I would like to use this to create an app that selects a file to run on a local machine. Maybe this isn’t the right way to go about it?

    Any help would be great.

    thanks.

  3. Tink says:

    It is not possible to get the path to the local file. This is a security feature.

    You can use FileReference locally but it requires a service side script. You could select the local file, upload it to a server , and then download it back into your desktop app.

    Other than that there is no current way to select a local file using the Flash Player.

  4. Rob Payne says:

    Hello, Its seems you know alot about Reference File Class and how to impliment the Syntax, Maybe you can help me with this question. Say for example, you draw and design a button on a stage and convert it to either the buttons or movie class. and you want to make that button download a file (MP3 or Wav, video Files etc.etc.) from your server you rent. What is the correct syntax to achieve that with action script 2 using the FileReference class? because I’ve tried and tried to make it work and it pops an error saying “Cant Load FileReference Class” or its alway giving an error. If you cant answer the question, can you lead me to a tutorial on how to make the buttons or movie class work in combination with FileReference class ? Thnx alot your truly Rob Payne…

  5. Tink says:

    Hey Rob

    Have you looked at the examples I put up here http://www.tink.ws/blog/files/flash8/DownloadExample.html (the source is actually in the Zip you download).

    You see if the code its currently targeting the ZIP file, so you would just need to change that tp match the path of your file.

    hope it helps

  6. Rob Payne says:

    I tried updated the flash player clicked the button and it doesnt do anything…. So now what do I do. There isnt a zip file that downloads, no dialog box to confirm where you want anything. it just sitting looking pretty, but with no functionality. Im using a pc at the library and they have high speed at best…

  7. Rob Payne says:

    can you email me the zip file ?

  8. Tink says:

    Strange works fine for me, ive just tested it. I click download it opens an OS window asking me where to save the file. i click save and it downloads.

    the source is here http://www.tink.ws/blog/files/flash8/FileReference.zip

Leave a Reply