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



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
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.
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?
The echo(” “) worked for me too… pretty frustrating trying to figure this out though. I should resort to Googling quicker than I do
In PHP, echo “”; still did not work for me, but echo “1″; did work.
Thank you for figuring this out!!
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();
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…
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″;
hello, i’ve tried everything mentioned and I still can’t get file uploads to work, has anyone come across any other fixes?
thanks.
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?
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!
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.
You are a life saver. This bug has been bugging me for hours.
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,
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..
ooooo Thank you mann……..
My Servlet was useless without these two golden lines….
response.getWriter().println(” “);
response.getWriter().flush();
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.
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…
Thanks, Abdul
You just saved me a lot of head scratching.
The final solution is that the server script responds ‘&bError=0&’
in PHP could it be
die(’&bError=0&’);
echo ‘&bError=0&’; exit;
etc.
THANK YOUUUUUUUUUUUUU! SO MUUUUUUUUUUUUUUUCH!
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
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.
Thanks a lot for this post…echo ” “(space in there) worked for me.
AWESOME, this worked perfectly!
echo ” “;
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!
echo “1″; work perfectly…
you saved my job!!!!
thanks a lot….
What about in ColdFusion?
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
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.
echo (”");
flush();
worked for my legacy PHP image uploader.
Thanks
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.
Thanks… this work!
The latest flash player fixed the issue for us. 10.0.22.87