Home > Flash and Actionscript > Workaround: FileReference onComplete is not fired on Mac OS

Workaround: FileReference onComplete is not fired on Mac OS

FileReference’s onComplete event is not fired on Mac version of Adobe Flash Player 8.
We faced similar problem and found the workaround, thanks to comment by Bob on Nirav’s blog.
There is simple workaround, you need to sent empty response from upload server-side script. In php, you would just do echo (""); after file-upload code. In ASP, you can do Response.Write (""). In Java servlet, you can do:

response.getWriter().println("");
response.getWriter().flush();

That’s all, now onComplete event should trigger on Mac’s Adobe Flash Player 8.
I am posting this with a specific subject line, so that developers can easily find by doing Google search.
Thanks to Bob and Nirav.

Categories: Flash and Actionscript Tags:
  1. hulja
    June 13th, 2006 at 08:31 | #1

    unfortunatly, this doesn’t seem to work for me. could you post an example? here’s what i’m using in my php:
    move_uploaded_file($_FILES['Filedata']['tmp_name'], “./photos/”.$_FILES['Filedata']['name']);
    echo “”;
    and still the same problem: works fine on any browser on my PC. on my mac, it’s uploading the file, but not triggering the onComplete statement.
    thanks

  2. hulja
    June 13th, 2006 at 08:36 | #2

    i put a space in the echo statement, like this:
    echo ” “;
    and it works now. excellent.
    thanks for finding this and posting a solution. i’ve tried everything, from file permissions, to optimizing my AS… and the solution is as simple as this.

  3. June 15th, 2006 at 23:24 | #3

    I implemented the “nothing” echo and all of our Mac people are still not getting that onComplete event to fire. I get some to work OK by adding a timeout in the onProgress event. In the onProgress event, when the bytes loaded equals the bytes total, I fire up a timer that “hand fires” the custom onComplete function. I set the onComplete event to fire that same function, as well. The code looks something like this:

    var uploadCompleteTimer:Number = -1;
    function uploadOnComplete( file:FileReference ):Void {
    clearInterval( uploadCompleteTimer );
    // DO WHAT YOU GOTTA DO for onComplete...
    }
    listenerUpload.onProgress = function( file:FileReference, bytesLoaded:Number, bytesTotal:Number ):Void {
    if( bytesLoaded == bytesTotal )
    uploadCompleteTimer = setInterval( function () {
    uploadOnComplete( file );
    }, 5000 );
    }
    listenerUpload.onComplete = uploadOnComplete;

    That makes it work SOMETIMES. We’re still getting hit and miss uploads on Macs. It is very definitely a Mac Flash player bug, IMHO. I’ve been able to get uploads to work more often in Firefox on a Mac, than on Safari.

    The files are not even making it to the server, sometimes. Does anyone have a better workaround?

  4. June 19th, 2006 at 03:53 | #4

    The echo(” “) worked for me too… pretty frustrating trying to figure this out though. I should resort to Googling quicker than I do ;)

  5. July 20th, 2006 at 22:35 | #5

    In PHP, echo “”; still did not work for me, but echo “1″; did work.
    Thank you for figuring this out!!

  6. Michael
    August 7th, 2006 at 19:56 | #6

    Hi,
    Thanks, this solved problem – I tried with Flash 9 as well – it seems like it is still not fixed there!
    An maybe something else: I have tested my flash on several server – on some the flash worked on mac on some not – with the workaround on all.
    I had to use for php:
    echo (”");
    flush();

  7. Lars
    August 30th, 2006 at 04:27 | #7

    It isn’t only a mac problem. I use windows XP with flash 8.
    I can’t get the onComplete to fire when I want to do the following. If i get an IOerror or so, i want to automattically retry the file.
    So I do this:

    luisteraar.onHTTPError = function(bestand:FileReference):Void {

    bestand.upload(”upload.php);

    }

    This will trigger the onProgress event and the PHP script moves the file to the correct place. But is doesn’t fire a onComplete!! I tried the MAC workarounds but is doesn’t work…

  8. Charlie
    October 16th, 2006 at 21:22 | #8

    I had the same issue – FileReference upload onComplete wasn’t being triggered with Flash 9 on a Mac.
    For some reason the fix above didn’t work – printing a string at the end of the upload.php script did tho…
    echo “&error=0″;

  9. January 5th, 2007 at 03:39 | #9

    hello, i’ve tried everything mentioned and I still can’t get file uploads to work, has anyone come across any other fixes?
    thanks.

  10. franklin
    January 10th, 2007 at 01:28 | #10

    totally different bug…
    Filereference on MAC gives me an I/O error if there are spaces in the file name.
    Anyone else run into this one?

  11. Gil Barbara
    January 23rd, 2007 at 12:16 | #11

    onComplete used to work on Mac without this hack in my old server.
    dual xeon, rhel4, ensim 4.1
    but stop on my new server, so I need to use this workaround..
    dual woodcrest, rhel 4, ensim X
    weird!

  12. Casey
    January 28th, 2007 at 02:33 | #12

    I had this same problem with Flash player 9 on a Mac while uploading over an SSL connection on a Drupal 5 powered site (PHP 5.2). I found that adding print “”; seemed to fire the onComplete event handler just fine.

  13. Dave
    March 15th, 2007 at 21:18 | #13

    You are a life saver. This bug has been bugging me for hours.

  14. Jakob
    April 2nd, 2007 at 15:16 | #14

    Thanks for sharing this problem.
    Scratched my head for a couple of hours earlier this morning.
    My script didn’t go for the echo ” “; But echo “1″; worked fine,

  15. Deepak Joshi
    July 25th, 2007 at 18:06 | #15

    Thanks
    It really worked for me.
    All I did was to put in Java Servlet.
    response.getWriter().println(” “);
    response.getWriter().flush();
    hats off to you all..

  16. gurmeet
    July 25th, 2007 at 18:19 | #16

    ooooo Thank you mann……..
    My Servlet was useless without these two golden lines….
    response.getWriter().println(” “);
    response.getWriter().flush();

  17. Evan
    February 9th, 2008 at 11:05 | #17

    It’s been a while I know, but I just wanted to say thanks for this. Solved my problem, and saved me hours of stress.
    Thanks so much.

  18. Rodolfo
    April 12th, 2008 at 01:42 | #18

    YEEESSSSSS
    thanks, man!
    Evan said: “saved me hours of stress”
    Me too!!!!!
    the echo ” ” has done it
    i’m running Leopard, in Safari it does not report the progress, but the onComplete is fired ok. On Firefox 3 beta 5 it is reporting the progress and firing the oncomplete…

  19. April 28th, 2008 at 21:33 | #19

    Thanks, Abdul :) You just saved me a lot of head scratching.

  20. June 28th, 2008 at 14:57 | #20

    The final solution is that the server script responds ‘&bError=0&’
    in PHP could it be
    die(’&bError=0&’);
    echo ‘&bError=0&’; exit;
    etc.

  21. Adriana
    August 26th, 2008 at 06:32 | #21

    THANK YOUUUUUUUUUUUUU! SO MUUUUUUUUUUUUUUUCH!

  22. September 5th, 2008 at 21:04 | #22

    Only Aral’s trick worked for me (PHP):
    die(’&bError=0&’);
    And even so it takes between 0.5 to 1 second to actually fire up the event.
    It’s awesome that after so many time this is not in the reference itself…
    Thanks a lot for sharing

  23. September 11th, 2008 at 03:01 | #23

    Excellent fix, thanks for posting.
    However, this behavior doesn’t seem like a bug (but I know, it is a bug). The fact that our scripts should tell flash that the upload actually worked seems like a smart thing to do.
    In fixing this, I would find it a plus if Adobe required that some response was written that could be checked, as this would make our applications that rely on Flash file uploads more flexible if an error did occur during upload.

  24. sunny
    September 16th, 2008 at 14:25 | #24

    Thanks a lot for this post…echo ” “(space in there) worked for me. :)

  25. October 27th, 2008 at 23:07 | #25

    AWESOME, this worked perfectly!
    echo ” “;

  26. October 30th, 2008 at 03:57 | #26

    I too would like to thank you for this post. it was the first one i found because of the title, and it solved the problem straight away… hazzah!

  27. vishal
    November 7th, 2008 at 18:09 | #27

    echo “1″; work perfectly…
    you saved my job!!!!
    thanks a lot…. :)

  28. February 3rd, 2009 at 00:47 | #28

    What about in ColdFusion?

  29. Aaron Christopher
    February 4th, 2009 at 05:09 | #29

    Thank you very much! This worked perfectly for me… just put echo(”1″); after your upload script, and that should cause the onComplete handler to fire on macs.
    Thanks again!
    Aaron

  30. February 27th, 2009 at 08:51 | #30

    Well I did all those listed above but still i could not make it to work on mac. here’s my upload script:
    foreach ($_FILES as $fieldName => $file) {
    $uploadFileName = $file['name'];
    $secret_test = $secret_test . $uploadFileName;
    $content1 = str_replace(” “, “_”,$uploadFileName);
    $content = ‘_’.$content1;
    move_uploaded_file($file['tmp_name'],$path.DS.$uploadFileName);
    }
    where do i place my echo here?
    BTW its a multi image upload also. Any information or correction on my code would be helpful. Thanks. :D

  31. philmill
    April 1st, 2009 at 02:45 | #31

    echo (”");
    flush();
    worked for my legacy PHP image uploader.
    Thanks

  32. bartman
    April 2nd, 2009 at 18:51 | #32

    Thank you so much,
    I spent hours finding this bug, concluding it could be solved with a simple echo “”;
    it makes you feel so stupid.
    But thanx alot.
    However in php4 the oncomplete event was triggered automaticcaly.

  33. April 23rd, 2009 at 22:58 | #33

    Thanks… this work!

  34. May 27th, 2009 at 15:48 | #34

    The latest flash player fixed the issue for us. 10.0.22.87