FileReference - on Mac, type is not available

nirav April 29th, 2006

For doing file uploads with Flash, you have to use the FileReference class. Now it’s a really nice feature - provides the basic features for uploading files and tracking their progress. There are two things I want to note about it on this post.

1. When the file is uploaded from Mac, the “type” property is not available.
The FileReference class has a property “type”, that gives you the extension (with the dot) of the file. This is very handy to check file types and reject the ones you don’t want to allow. But when you upload a file from the Mac, the “type” property is blank. I am not sure if this is a Mac issue or a Flash issue. But as of now, the best way for you to find the extension of the file is to substr it.

var fName = f.name; // f is the FileReference Object
var ext:String = fName.substr(fName.lastIndexOf(”.”), fName.length);
ext = ext.toLowerCase();

2. You can’t return data from the server to Flash when upload completes
When you provide file upload feature in your application, many of the times, you want to return an ID of the uploaded file or its URL. The FileReference class does not support this. You have to make another call to the server to get any additional information. The FileReference will simply give you “onComplete” event when the server returns HTTP status code 200. It discards any data you send from the server in the response.

It would be great if we can pass a url encoded string back and the values were available to the onComplete event.

Comments RSS

Leave a Reply