Flash upload progress bar skips to 100%

I have a flash uploader with a progress bar.  The progress bar skips immediately to 100% as soon as the file starts uploading, even if the file is large (10MB+).  How can I get the progress bar to update accurately?  I'm using AS2 with the FileReference class.  Working incorrectly in both FF and IE.
listener.onProgress = function(fr, bytes_loaded, bytes_total) {
	//update the progress bar during upload
	var percent = Math.round(bytes_loaded / bytes_total);
	t_percent.text = percent * 100;
	bar._width = max_w * percent;
};

Open in new window

LVL 1
rmirabelleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TheDauntlessCommented:
bytes_loaded /bytes_total will return a value between 0 and 1. You then use Math.round() so it will become 0 at first and 1 near the end.

Multiply by 100 BEFORE you round it:

var percent = Math.round(bytes_loaded / bytes_total * 100);
rmirabelleAuthor Commented:
I see that my code was wrong, but it was right before I started messing with it.  Same problem.  Uploading a 1.3MB image and the progress meter skips instantly to the end.  Another test, I uploaded a 50 MB file and was actually able to see the progress bar progress - took just under 1 second to go from 0 to 100, as though the progress that was being measured was the bytesLoaded into RAM or into the swf and not the progress of the file to the server.  

I've seen it mentioned somewhere that the server and cache settings could have some effect.  I'm running Apache 2.2.6 on Linux with PHP 5.3 and the default session cache settings.


listener.onProgress = function(fr, bytes_loaded, bytes_total) {
	//update the progress bar during upload
	var percent = Math.round(bytes_loaded / bytes_total * 100);
	t_percent.text = percent;
	m_percent._width = max_w * percent / 100;
	t_status.text = 'uploading...';
};

Open in new window

rmirabelleAuthor Commented:
FOUND IT!  After hours and hours of head scratching, I found the problem (and I guess, the solution).  One thing I noticed is that I was checking a few of the commercially available file upload utilities out there and it seemed that at least one other popular solution that used a Flash based file uploader exhibited the exact same issue when I ran their demo - the upload progress bar would skip directly to 100% even for large files.

The solution is a bit strange.  The culprit? Kaspersky Anti-virus!  Disabling Kaspersky immediately fixed my uploader and progress reporting now works perfectly.  I'll experiment with other settings - perhaps completely disabling it is overkill, but at least I know what's been causing the problem.  What Flash and Kaspersky have to do with each other I may never know, but I'm a happy camper anyway.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
vrobisonCommented:
The reason that Kapersky shows 100% is that when the browser uploads content, a local hook to process web traffic intercedes, much like a proxy, and the bytes sent by the file upload happens locally  (and very quickly), so Flash thinks the file is fully uploaded.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.