views:

127

answers:

2

I've been putting together a small personal website in rails and have gotten to the point where I need to be able to upload files. This is an almost trivial task and took no time at all.

What is taking time - and is slowly sapping my sanity - is the task of providing the user with an upload progress bar. I've seen at least a dozen solutions now and they all seem to have one thing in common - they require the installation of a module on the web server.

Given that I have no control over my server that and it seems unlikely that the hosting company will ever undertake to install any such animal, I'm in a bit of a bind. What makes this truly maddening is that involving the server in this process in any way, shape, or form, is absolutely unnecessary.

Think about it: Your browser opens a socket to the remote server and starts sending data. Your browser knows exactly how many bytes are to be sent, and, thanks to the magic of TCP acknowledgments, is also aware of how many bytes have arrived at the server side. So why in the Name of The Flying Spaghetti Monster is there no simple way to present this data to Javascript without futzing around with the blasted server?

A: 

I completely agree, unfortunately there's no standard api for that across browsers. However even if that existed, the server would need to participate. You cannot trust how much data you have sent, HTTP needs an acknowledge. Therefore you would need the server telling you if datagram #526 is received. If there were an API it could be a good guess, but not really the same thing :S

Check www.faqs.org/rfcs/rfc1867.html

If you can ping the server, you could simulate it (with no confidence).

eipipuz
+1 "no standard api". However I disagree with your assement that the server assistance would still be needed to provide progress info. Just knowing how much of the total bytes to be sent has been handed over to TCP for transport would provide a meaningful enough progress bar.
AnthonyWJones
You wouldn't have to guess. These data are easily available to anyone capable of bashing together a Berkeley Sockets TCP client... which would include any browser software team.
+5  A: 

The true limitation here are HTML Forms. They were invented over 10 years ago when the upload of larger files seemed completely unfeasible. So they provide you only with one callback: when the entire upload is done (ACTION parameter).

Luckily, there are some free flash based uploaders out there that offer progress bars. Don't worry, most of them will degrade gracefully (providing a simple file upload field if the user has no flash). All options can be controlled via Javascript. And, they don't require any special server-side infrastructure.

Check swfupload.org

Franz
swfupload is great.I've used it a lot. +1 from me :)
the_drow