in Technology

FileReference – on Mac, type is not available

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.

Write a Comment

Comment

12 Comments

  1. Another Mac FileReference thing is to do an empty echo in the file-upload php so the onComplete handler does fire.

  2. Oh yes! That’s so true. You don’t get the onComplete event on Mac if you do not have an empty echo / Response.write on the server. You will get 100% complete in the progress event though.

    Thanks Bob!

  3. Hello,

    I am still having a similar problem to this and nothing I try seems to allow the onComplete to fire (in any browser, Safari, Firefox, or Opera).

    I’ve now got my PHP looking like this:

    header(‘HTTP/1.1 200 OK’);
    header(‘Status: 200 OK’);
    move_uploaded_file($_FILES[‘Filedata’][‘tmp_name’], ‘./files/’.$_FILES[‘Filedata’][‘name’]);
    chmod($_GET[‘path’].$_FILES[‘Filedata’][‘name’], 0777);
    echo (“&error=0”);
    flush();

    I’ve checked my paths and permissions and the files are getting uploaded, it’s just the onComplete that never ever fires.

  4. Hi Mark,

    Could you try this:
    * Are you sure there is nothing else that is being sent to the browser before you send the header?
    * Do an empty echo – rather than error=0

    :Nirav

  5. One big dissapointment for me was that flash wont send the mime type to the server side script.
    This is making open upload forms less secure as you cant check the mime type on the server like with xhtml forms.

  6. I am having big problems with the FileReference class. My script doesn’t work at all with mac. It seems like everyone else has problems with the onComplete-handler but at least the files get uploaded to the server. Has anyone experienced the same problem as me? On a PC the files get uploaded ok, but on Mac absolutely nothing happens.

  7. Having the same problem with the fileReference class. Works great with PC, but nothing happens on the mac. The upload.php script returns HTTP ERROR 404. Getting sick and tired on these mac issues. I have tried editing the .htaccess file but that results in a internal server error (500). What can be done? Hoping for an answer…

  8. Hello everyone,

    May be you would be interested to look at another flash upload utility:
    http://www.easyalgo.com/eaflashupload.aspx. It has three different user interfaces and many advanced features such as: send variables as form fields values, retrive browser cookie, assign description for each file, JavaScript API, compatibility with Flash Player 10 security restrictions.