Flash upload progress bar skips to 100%

rmirabelle
rmirabelle used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
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);

Author

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

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.

Commented:
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.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial