FileReference: Room for Improvement
One of my latest projects for DecisionLens required me to use Flash 9 to upload and download files from a web server. In my case, a java servlet. Tink has written an excellent tutorial to get you started with FileReference, it can be found here:
Tink’s FileReference Tutorial + Source
His example is great, it covers all the basics of the FileReference class but in my working with the class, I discovered a few other nuances that may prove helpful..
Authorization
In my scenario it was necessary to authenticate the client BEFORE uploading the file. This required passing a username and password to the java servlet. Unfortunately the FileReference class can only pass variables to the script via HTTP_GET variables- this poses a security threat, exposing the username and password. To get around this I used LoadVars.sendAndLoad- passing the username and password via HTTP_POST to a server side script [java servlet in this case]. The script returns a unique sessionID that is passed back to the script via HTTP_GET with the FileReference.upload() command. If the passed sessionID matches the stored server-side sessionID the upload is allowed and the session is deleted, otherwise it is rejected and an HTTP error code is used to pass information back to the client [see next workaround]. This enabled the client to be verified and the username and password information to be secured.
.
Returning Information to the Client
Another downfall of the FileReference class is that it provides no method of retuning information to the client about the upload. Let me rephrase that- it can return infomation to the client, but only very simple HTTP error codes. So there is no way to return messages or variables from the script, to the client. To work around this we assigned certain http error codes to certain siutations- ie: HTTP401 = unathorized user, HTTP400 = File Already Exists, HTTP 500 = Java Exception / Server Error. Granted these are not the most ideal ways of returning information to the client but given the structure of the class, it is the only way to accomplish this goal.
Overall the FileReference class is a great tool for moving files to and from a server. While it certainly has its downfalls I really think the pros outweigh the cons. We can only hope that Macromedia/Adobe will address the many pertinent issues pointed out on livedocs.
